标签:style blog http os io 数据 ar 2014 问题
#include "iostream" using namespace std; //讨论初始化构造函数 //主要讨论在有虚函数情况下的初始化构造函数问题 //含有虚函数的类对象维护一个vptr指向类中的vtbl class ZoolAnimal { public: ZoolAnimal(){} ~ZoolAnimal(){} virtual void animates(){ cout << "ZoolAnimal::animates()" << endl; } virtual void draw(){ cout << "ZoolAnimal::draw()" << endl; } private: }; class Bear : public ZoolAnimal{ public: Bear(){} ~Bear(){} virtual void animates(){ cout << "Bear::animates()" << endl; } virtual void draw(){ cout << "Bear::draw()" << endl; } virtual void dance(){ cout << "Bear::dance()" << endl; } private: }; int main() { /*bear类型的数据初始化bear数据*/ Bear yogi; Bear carp = yogi; carp.animates(); carp.dance(); carp.draw(); /*bear数据初始化ZoolAnimal类型*/ ZoolAnimal zAnimal = carp; zAnimal.animates(); zAnimal.draw(); return 0; }
标签:style blog http os io 数据 ar 2014 问题
原文地址:http://blog.csdn.net/licong_carp/article/details/38778907