I have two classes: Meter
and Feet
. Each has a method that converts its value into the other and returns the other object. For example, Meter
has a method toFeet()
that returns a Feet
object, and vice-versa.
I have used forward declaration. I have also tried including and (as suggested in another post) not including other class' header files.
Meter.h
...
class Feet; // forward declaration
class Meter {
public:
...
Feet toFeet() const { return Feet(...); }
...
};
Feet.h
...
class Meter; // forward declaration
class Feet {
public:
...
Meter toMeter() const { return Meter(...); }
...
};
I get the following error:
In member function 'Feet Meter::toFeet() const':
error: return type of 'class Feet' is imcomplete
{
^
error: invalid use of incomplete type 'class Feet'
error: forward declaration of 'class Feet'
So what conceptual stuff did i miss here?
EDIT: The post was marked as duplicate to one in which the answer is forward declaration. But I had tried that before posting this problem.
Anyway, my accepted (and very simple) solution was to separate declarations and definitions of methods.