Overriding error.. pls advise me
I kept getting this error:
Line3D.h:18:13: error: invalid covariant return type for ‘virtual Point3D Line3D::getPt1()’
Line2D.cpp:41:9: error: overriding ‘virtual Point2D Line2D::getPt1()’
Line3D.h:20:13: error: invalid covariant return type for ‘virtual Point3D Line3D::getPt2()’
Line2D.cpp:52:9: error: overriding ‘virtual Point2D Line2D::getPt2()’
The following is at these portions:
Line3D.h:18:
Point3D getPt1();
Line2D.cpp:41:9
1 2 3 4
|
Point2D Line2D::getPt1()
{
return pt1;
}
|
Line3D.h:20
Point3D getPt2();
Line2D.cpp:52
1 2 3 4
|
Point2D Line2D::getPt2()
{
return pt2;
}
|
What have i done wrong here?
The requirement states:
+ getPt1 () : Point2D
+ getPt2 () : Point2D
+ getPt1 () : Point3D
+ getPt2 () : Point3D
The bottom function inherit from the function on top..
Any help on this error?
You cannot have different return types with the same function name. You may name it like so:
1 2
|
Point3D get3DPt1();
Point2D get2DPt1();
|
Thanks
Topic archived. No new replies allowed.