#include <ostream.h>
Class B
{
public:
virtual void print() const
{
cout << "printB" << std::endl;
}
};
class A
{
public:
virtual void print(const B* b) const
{
cout << "printA" << std::endl;
b->print();
}
};
main()
{
cout << "test" << std::endl;
A* a;
B* b;
a = new A();
b = new B();
a->print(b);
}
Note:
1. the const at the end of the function declaration: indicates that the "this" parameter to the function is const.
2. use the const because it don't modify the object.