I'm now fairly confident I understand what you were saying with the Animal-Dog-Cat example:
Code:
// http://cboard.cprogramming.com/cplusplus-programming/146473-overloading-overriding-hiding-help.html#post1092465
#include <iostream>
using std::cout;
using std::endl;
class Animal
{
public:
virtual void speak()
{ cout << "Animal::speak()" << endl; }
};
class Dog: public Animal
{
public:
void speak(int)
{ cout << "Dog::speak()" << endl; }
};
class Cat: public Animal
{
public:
void speak()
{ cout << "Cat::speak()" << endl; }
};
int main(void)
{
Animal a;
Cat c;
Dog d;
// Classic inheritence/polymorphism: overridden base class function
a.speak();
c.speak();
// except for this one, which does not override Animal::speak()
// but instead hides it from a derived class object
d.speak(1);
// d.speak(); // this would fail
cout << endl << "Now calling speak() using base class pointer" << endl;
Animal* aptr = 0;
// set to Animal (base) class
aptr = &a;
aptr->speak();
// set to Cat
aptr = &c;
aptr->speak();
// set to Dog
aptr = &d;
aptr->speak();
return 0;
}
Initially I wrote it without the improperly overridden Dog::speak() function, then to illustrate what you were talking about I went back and changed it to accept an int.
Thanks for reading that forum thread on L.U.'s site, and for the additional tips. I think you're right about the concepts becoming clearer through application.
When I was reading the last chapter in Beginning Visual C++ 2008 I was having a hard time understanding some of the operator overloading concepts, but it wasn't until I had do the exercises that I was able to sort things out (with a lot of help from the regulars here).
I'm hoping the same thing will happen at the end of this chapter.
Thanks again.