c++ - Class member variable -
I am starting to learn c ++ and as far as I can get, I am the only form of primitive type class members Can find in / P>
The following is giving me an error: missing type identifier - int eclipse?
class CarManager {public: zero drive (); Private: car car; };
I tried all the combinations that I could think of:
car car = new car (); Car * car = new car (); Car and car = new car ();
Everyone has their own errors.
First of all, car
should be defined: before the CarManager definition Add #include "Car.h"
.
Then, if the car's characteristic is an object (as it is proposed in your example), it should be a default constructor or be started on the Caraminer Creator:
Class Employer {Public: Caraminer (): Car (... construction parameters ...) {} // to be transferred to CPP file, of course! Zero drive (); Private: car car; };
Note: If this is an indicator ( car * car;
) or a reference ( car and car;
), Car.h is required to include, a forwarded declaration ( class car;
instead of #include "Car.h"
). After that, start the pointer / reference when including Car.h from CarManager.cpp.
Gene
Comments
Post a Comment