摘要:
C++中构造函数中调用虚函数的问题在构造函数中调用虚成员函数,虽然这是个不很常用的技术,但研究一下可以加深对虚函数机制及对象构造过程的理解。这个问题也和一般直观上的认识有所差异。先看看下面的两个类定义。struct C180{ C180() { foo(); this->foo(); } virtual foo() { cout << "<< C180.foo this: " << this << " vtadr: " << *(void**)this << endl; }}; 阅读全文
随笔档案-2011年6月24日
C++中默认构造函数的生成(哪些情况会产生默认构造函数)
2011-06-24 14:13 by htc开发, 440 阅读, 收藏,
摘要:
#include <iostream>#include <cstdlib>using namespace std;//#define FOO_NON_DEFAULT_CONSTRUCTclass A{public: A():a(0){ cout << "construct..." << endl; } A(int value):a(value){ cout << "construct..." << endl; } ~A(){ cout << "deconstru 阅读全文
浙公网安备 33010602011771号