Wednesday 15 May 2013

Conversion Constructor in C++ -


Program error below is 'incomplete type square rectangular' and 'forwarding declaration of square rectangle' to any header file How to fix it without editing? Is there no way to convert using constructor?

 Add  & lt; Iostream & gt; Include & lt; Math.h> using namespace std; Square rectangle; Square polar {int radius, angle; Public: Polar () {radius = 0; Angle = 0; } Polar (rectangle) {radius = sqrt ((r.x * r.x) + (ryy * r.y)); Angle = aaa (ry / rx); } Zero getData () {cout & lt; & Lt; "Eder Radius:"; CIN & gt; & Gt; Radius; Cout & lt; & Lt; "Einter angle (in radians):"; CIN & gt; & Gt; Angle; Angle = angle * (180 / 3.1415926); } Zero shodata () {cout & lt; & Lt; "Converted data:" & lt; & Lt; Endl; Cout & lt; & Lt; "\ TRADIUS:" & lt; Radius & lt; & Lt; "\ N \ tangle:" & lt; & Lt; Angle; } Friend Rectangle :: Rectangle (Polar P); }; Square rectangle {int x, y; Public: Rectangle () {x = 0; Y = 0; } Rectangle (polar p) {x = (p.radius) * cos (p.angle); Y = (p.radius) * Sin (P. Gangal); } Zero getData () {cout & lt; & Lt; "Enter X:"; CIN & gt; & Gt; X; Cout & lt; & Lt; "Enter Wi:"; CIN & gt; & Gt; Y; } Zero shodata () {cout & lt; & Lt; "Converted data:" & lt; & Lt; Endl; Cout & lt; & Lt; "\ TX:" & lt; & Lt; X & lt; & Lt; "\ N \ tY:" & lt; & Lt; Y; } Friend polar (rectangle); };  

How to fix it without editing any header file.

You can not define the definition after the definition of rectangle so that rectangle is complete Where the constructor needs to use it.

Just declare the constructor in class definition:

  polar (rectangle);  

And define it somewhere else; After defining rectangle , it will either need to mark inline in the source file, or in the header.

Personally, I make it clear to define all the members in two headers, one per square and in the source files (unless I have not proved that they are performing Inline is needed for reasons). After this the headers are required to declare only the second category, and it must be included only in the source files which implement or use classes.


No comments:

Post a Comment