|
ex7-9.cpp - Example 7-9 Non-virtual Functions |
// File: ex7-9.cpp
#include <iostream>
using namespace std;
class B
{
public:
B() { cout << "B ctor called for " << this << endl;}
void funk1() { cout << "B::funk1() called for " << this << endl; }
void funk2() { cout << "B::funk2() called for " << this << endl; }
};
class D : public B
{
public:
D() { cout << "D ctor called for " << this << endl;}
// Override funk1()
void funk1() { cout << "D::funk1() called for " << this << endl; }
};
int main(void)
{
B b;
D d;
cout << endl;
b.funk1();
d.funk1();
cout << endl;
b.funk2();
d.funk2();
cout << endl;
B* pB;
pB = &b;
pB->funk1();
cout << endl;
pB = &d;
pB->funk1();
cout << endl;
cout << "size of b = " << sizeof b << endl;
cout << "size of d = " << sizeof d << endl;
return 0;
}
CIS27: Programming in C++ Instructor: Joe Bentley