🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ Workshop - Inheritance (Ch. 12)

Started by
39 comments, last by Dbproguy 16 years, 1 month ago
I just finished Chapter 12, the chapters seem to get easier and easier as I go on in the book, ever since chapter 6.

Chapter 12 Quiz

1. What is derivation?
Having a is-a relationship, like a Dog is-a Mammel.

2. What happens if you try and derive from a class which has not yet been declared.
The compiler will generate an error.

3. What is the purpose of declaring member variables as protected?
They are treated as private but classes derived from the class containing protected variables can access them.

4. When instantiating an object which is derived from one or more base classes, which constructors are called, in what order?
The derived object's constructor is called last, like a Dog is a Mammal which is an Animal, Animal would be called first, then Mammal then Animal.

5. What about destructors? What order are they called in.
The derived object's destructor is called first, like a Dog is-a Mammal which is-a Animal, Dog would be called, then Mammal then Animal.

6. What is it called when a derived class replaces the functionality of a base class with its own implementation?
Overriding

7. If you’ve overridden a method in a derived class, is it still possible to access the base class version? If so, what’s the syntax?
Yes, If the derived object was Fido, the base class was Mammal the syntax to move would be Fido.Mammal::Move();

8. What does declaring a method as virtual do?
Creates a simpler way to access overridden base-class methods.

9. Can virtual functions be used on non-pointer, non-reference variables?
No

10. When should you declare the destructor of your class as virtual? What happens when you delete a base pointer to a derived class with a non-virtual destructor.
Anytime any function in the class is virtual.

11. Can constructors be virtual? Can copy constructors be virtual?
Constructors can't but using the Clone function copy constructors can.
--Dbproguy - My Blog - Tips, Opinions and Reviews about C++, Video Games, and Life

This topic is closed to new replies.

Advertisement