Forgive me if the question is a duplication....I was not able to get a satisfying answer, so posting the questing in my way....
Consider the sample code
class Base {
protected:
Base() {}
};
class Derived:public Base {
public:
void func() {
Base obj;
}
};
The above code will thow a compilation error saying the constructor of Base is protected. But if I create an Object of Derived class in main the constructor of Base class is getting called( I know its called internally by the Derived class constructor), which means Base class constructor can be called from a Derived class function. Then why we are not able to create an Base class object within a derived class function...?
And one more thing....is there any other way to instantiate an object of a class whose constructor in protected, other than inside a method of the same class(as we do while creating Singleton )...?