home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ for Dummies (3rd Edition)
/
C_FD.iso
/
CHAP18
/
CHAP18_4.CPP
< prev
Wrap
C/C++ Source or Header
|
1996-09-02
|
620b
|
38 lines
// Chap18_4.cpp
#include <iostream.h>
class Base
{
public:
virtual void fn(int x)
{
cout << "In Base class, int x = " << x << "\n";
}
};
class SubClass : public Base
{
public:
virtual void fn(float x)
{
cout << "In SubClass, float x = " << x << "\n";
}
};
void test(Base &b)
{
int i = 1;
b.fn(i); //this call not bound late
float f = 2.0F;
b.fn(f); //neither is this one
}
int main()
{
Base bc;
SubClass sc;
cout << "Calling test(bc)\n";
test(bc);
cout << "Calling test(sc)\n";
test(sc);
return 0;
}