0

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*
}
Community
  • 1
  • 1
Rick
  • 327
  • 2
  • 3
  • 6
  • 1
    Do you have a compiler? Can't you just test these things? – Andrei Jun 05 '11 at 20:35
  • @Andrei: Its easy to test when you know how. But does it looks like the OP knows how to do the test? Based on the question itself it seems unlikely. Now it may have been useful for you to explain a simple test (Like binding a reference and see the compile fail). – Martin York Jun 05 '11 at 20:36
  • @Martin: You could add a test demonstrating this to your answer (including requisite `// will not compile` comments, etc). – Merlyn Morgan-Graham Jun 05 '11 at 20:37

1 Answers1

6

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;
}
Martin York
  • 257,169
  • 86
  • 333
  • 562