Reputation: 2141
So I have three classes, lets call a Car, an Engine, and a Stator Motor. Each one of them depends upon the other. So Car HAS AN engine, and an Engine HAS A Stator Motor.
Here is how I declare the classes in C++:
class Car {
private:
bool Has_Windows;
Engine _Eng_;
public:
Car(bool Windows, Engine _Eng): Has_Windows(Windows), _Eng_(_Eng){}
};
Class Engine {
private:
bool Racing_Car;
Stator_Motor s_motor;
public:
Engine(bool Car_Type_Engine, Stator_Motor _s_motor): Racing_Car(Car_Type_Engine),
s_motor(_s_motor){
}
};
Class Stator_Motor {
private:
bool AC_220;
public:
Stator_Motor(bool Voltage_Type): AC_220(Voltage_Type);
};
And in main, I initialize C as:
Car C(true, Engine(true, Stator_Motor(true)));
Now here is the problem, though when I am writing this down, the Intellisense in Visual Studio does find Stator_Motor constructor definition, but once I type it, it says it can't find no definition of Engine that has similar arguments. Why is this?
Upvotes: 0
Views: 75
Reputation: 409216
In C++ you need to declare the symbols you are using before you are using them. And as you don't use pointers or references for the classes, you actually have to define them before using them.
So you have to define the classes in the opposite order:
class Stator_Motor { ... };
class Engine { ... };
class Car { ... }
Also, your constructor in Stator_Motor
is wrongly named.
Upvotes: 1