标签:main new ace void space nbsp logs out ring
先是代码:
#include<iostream> #include<string> using namespace std; class Demo { public: Demo(string s); ~Demo(); private: string m_s; }; Demo::Demo(string s):m_s(s){} Demo::~Demo(){cout<<m_s<<endl;} void func() { Demo boj1("1"); } Demo obj2("2"); int main() { //局部对象 Demo obj3("3"); Demo *pobj4=new Demo("4"); func(); cout<<"main"<<endl; return 0; }
然后运行结果是
1 main 3 2
这里分析下堆栈和构造函数初始化中的函数调用顺序:
标签:main new ace void space nbsp logs out ring
原文地址:http://www.cnblogs.com/enyala/p/7637282.html