/////////////////////////////////////////////////////////////////// // operations.cpp - Solution of MT#2-Q5, MT#3-Q6, and MT#4-Q8 // // // // This is a demo showing how what happens when some polymorphic // // code executes. // /////////////////////////////////////////////////////////////////// #include #include typedef std::string str; class B { public: virtual ~B() {}; str say() { return typeid(*this).name(); } virtual B* make() { return new B(*this); } }; class D : public B { public: D* make() { return new D(*this); } }; class A { str say() { return "class A"; } }; class B2 { public: virtual ~B2() {}; str say() { return typeid(*this).name(); } }; class D2 : public B2 { public: A a; }; void fun1(B2 b[], int size) { for(int i=0; i