Possible Duplicate:
Default class inheritance access
I know I can set the protection level when I declare a subclass from a superclass as in:
class Dog : public Pet {
*blah, blah, blah*
}
But what does the protection level default to in this case?
Class Dog: Pet {
*blah, blah, blah*
}
For a class it is private
class Dog: Pet // Pet is inherited privately.
{}
For a struct it is public.
struct Dog: Pet // Pet is inherited publicly.
{}
Simple test:
class Pet {};
class DogClass: Pet {};
struct DogStruct: Pet {};
int main()
{
DogClass dogClass;
// Pet& pet1 = dogClass; This line will not compile.
DogStruct dogStruct;
Pet& pet2 = dogStruct;
}
精彩评论