Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Beginner
Apr 24, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Constructor for a Protected Class

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_Message
CC -c Message.cc 
"Message.h", line 50: Error: Could not find 
Message::Message(const char[11], String, int) to initialize base 
1 Error(s) detected.
*** Error code 1
make: 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.

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.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date