#include <iostream> using namespace std; class test { public: test(int iVar):m_iVar(iVar),m_iCount(0){m_iCount=++s_iCount;cout<<"I am in constructor and I am the "<<s_iCount<<endl;}; test(){test(0);}; void print(){cout<<m_iVar<<endl;cout<<s_iCount<<endl;}; ~test(){cout<<"I am in destructor and I am the "<<m_iCount<<endl;}; private: int m_iVar; int m_iCount; static int s_iCount; }; int test::s_iCount = 0; int main() { test t;//a test t1();//b test();//c system("pause"); return 0; }
谁能解释a,b,c单独运行时三种调用的结果
test(){test(0);};
这句不是调用构造函数,而是生成了一个临时对象
嗯,我知道,但是对这三种情况的结果不太明白
比如test t1()到底是干啥? 为什么什么都不显示,其他两种我明白含义