Executable size

Started by
10 comments, last by level10boy 21 years, 7 months ago
Bjarne says in TCPPPL that polymorphic behavior can ONLY be exhibited with pointer or reference types.

See below:


  #include <iostream>using namespace std;class A{public:	virtual void out() { cout << "Out from class A" << endl; }};class B : public A{public:	void out() { cout << "Out from Class B" << endl; }};void main(){	A a;	B b;	a.out(); // echoes "Out from class A"	b.out(); // echoes "Out from class B"	A new_a = b;	new_a.out(); // echoes "Out from class A", as expected,				// since we are _COPYING_ the parts of b 				// that are of class A over to a new object of class A	A* p_a = &b	p_a->out(); // echoes "Out from class B", because it''s a pointer				// type, and accesses the vtbl	A& r_a = b;	r_a.out(); // echoes "Out from class B", because (again) it''s a reference type (points-to)}  
daerid@gmail.com
Advertisement
That''s what I thought originally before I became wayward.

Thanks.
It's not what you're taught, it's what you learn.

This topic is closed to new replies.

Advertisement