1

When having a base class with pure virtual methods this makes it so that the class can not be instantiated. If I have regular methods and attributes in this base class does the derived classes still inherit those as normal?

For e.g. a getter and setter for an attribute.

1
  • 1
    Why don't you try it out yourself? Commented Feb 19, 2010 at 4:02

2 Answers 2

2

Yes, all methods are inherited.

Sign up to request clarification or add additional context in comments.

4 Comments

Private methods are inherited just as well - they're private, sure, but friends can still see them.
They are still inherited even if private - it's just that they are inherited as private methods etc, so they can't be referenced. For example, an inherited private field still takes up space in instances of the class, and still holds a value that might affect the results from (non-private) inherited methods.
Private inherited functions can be called by the base class. So, they can still be used to change behavior. You just can't call them outside of the base class. All private, protected, and public indicate is who can call the functions.
Thanks. Fixed. For some reason I assumed he wanted to know if other classes can access it.
0

As Moron said, try it yourself. But, to put more structure around the topic...

There is interface inheritance (what methods can I call on an object?) and implementation inheritance (what code gets called when I call this method on this object?). Pure virtual methods provide interface inheritance, but not implementation inheritance. A virtual (but non-pure) method provides both, with the option to allow a derived class to provide a different implementation. A non-virtual method provides both, without the option to allow a derived class to provide a different implementation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.