Code:
#include <iostream> using namespace std; class A { public: A() {cout << "constructor A" << endl;} A(A& a) {cout<<"copy A"<<endl;} virtual void Test(){cout <<"A test" <<endl;} }; class B:public A { public: B() {cout << "constructor B" << endl;} B(B& b) {cout<<"copy B"<<endl;} void func(){Test();} virtual void Test(){cout <<"B test" <<endl;} }; class C:public B { public: C() {cout << "constructor C" << endl;} C(C& c) {cout<<"copy C"<<endl;} virtual void Test(){cout <<"C test" <<endl;} }; void main() { C c; ((B*)(&c))-> func(); ((B)c).func(); cout.flush(); int i; cin >> i; } //output is here: constructor A constructor B constructor C C test constructor A//Here is my question copy B B test
((B)c).func(); gives out the following results:
constructor A//Here is my question
copy B
B test
Please help me.Thanks!
Comment