I am having a problem with the use of a class member that does not seem to be constructed.
I have a name space called "DogActivity".
In this name space there are two classes " DogSounds and Bark".
In the Bark class I have a private: instance of DogSounds.
Now in the constructor of the DogSounds class there is a private: int variable called NumSounds that is initialized to 0.
The problem is if i create an instance of DogSound in my main program the constructor is called and the NumSounds variable is set to 0 as planned.
But
If i create an instance of Bark in the main program the constructor of DogSounds is never called and NumSounds is never initialized.
here is an example of my namespace with classes.
namespace DogActivity
{
class DogSounds
{
public:
DogSounds() { NumSonds = 0;}
private:
int NumSounds;
};
class Bark{
private:
DogSounds dogSounds;
};
}
Now here is how i would use in main
using namespace DogActivity;
int main ( int argc, char * argv[] )
{
Bark bark;
// Do work with bark bellow
}
But when I create the instance of Bark the privat: dogSounds' variable "NumSounds" is never set to 0. The Constructor of dogSounds is never called, why is this? shouldn't the constructor of dogSounds be called as soon as i create an instance of Bark? what might i be doing wrong here?