Tabian, Thank you for your explanation.
I read about constructors and destructors for derived classes and understood in principle about their order of execution. I didn't really understand the consequences of that until your post.
I hadn't realized that constructors were having an impact on my code because I had not created any. But of course, the compiler creates default constructors.
I am a bit torn between trying to further my understanding of derived classes by creating my own constructors, rather than relying on the compiler's default constructors, and furthering the development of my project. However, I expect that somewhere down the road the compiler's default constructors won't be adequate and I will have to write my own.
Still, I will wait a bit because some quick experiments with constructors have yielded the following.
1 2 3 4 5 6 7 8
|
class Goods {
protected:
double unit_labor;
double price;
public:
Goods(double, double) {}; // constructor
};
...
|
The above code yielded the following "error C2512: 'Country' : no appropriate default constructor available". This error was attached to the line (45) where 'home' was instantiated to the class 'Country'. Some research revealed that a programmer-defined non-void constructor in one class requires programmer-defined constructors for all classes. (As I understand things.)
1 2 3 4 5 6 7 8
|
class Goods {
protected:
double unit_labor;
double price;
public:
Goods() {}; // constructor
};
...
|
Whereas the above code compiles and runs correctly.
So I would have to learn about void and non-void, and, default and explicit, constructors in ordinary classes, base classes, derived classes, and nested classes. It sounds very complicated!