I have a base class Point
from which I inherit in Point3D
. However, for some reason class Point
must always return Point3D
You can't inherit from an incomplete type. You need to structure your code as follows:
class Point3D;
class Point
{
// ...
Point3D add(const Point &);
// ...
};
class Point3D: public Point
{
// ...
};
Point3D Point::add(const Point &)
{
// implementation
}
Function return types may be incomplete, which is why your class definition of Point
works like this.
I trust you can figure out how to split that across header and source files. (For example, the first two parts can go in Point.hpp
, the third in Point3D.hpp
which includes Point.hpp
, and the final implementation can go in Point.cpp
which includes Point.hpp
and Point3D.hpp
.)