Question:
How do I create a constructor for a protected member of a class? I have declared the function in the header file but not defined the definition.The error message I get from the compiler is below:
make test_MessageCC -c Message.cc "Message.h", line 50: Error: Could not find Message::Message(const char[11], String, int) to initialize base class.1 Error(s) detected.*** Error code 1make: Fatal error: Command failed for target `Message.o'
The line where the error message is pointing to is to an individual message and I believe the error message is saying it can’t initialize the base class message.
Answer:
You can declare a constructor protected only in base classes or classes that should have no instances (for example, abstract classes). A derived class can access all the protected members of its public or protected base class. Therefore, it can invoke the base class’ constructor even if it’s protected. However, a containing class doesn’t have this privilege and is therefore prohibited from accessing a non-public constructor of its member object. Either declare your constructor public, or make it a base class.