最近面试的时候被问到一个问题是,在C++中,能否在类的成员函数中调用delete this,后来网上查了一下资料,关于这个问题说得比较好的有http://blog.sina.com.cn/s/blog_4b4cf2af0100ywgv.html 但是自己尝试了一下,还是有点区别的. 我写了如下代码: class A { public: A() { member = ; } ~A() { member = ; } int test() { cout << member << endl
C++中的class从面向对象理论出发,将变量(属性)和函数(方法)集中定义在一起,用于描述现实世界中的类.从计算机的角度,程序依然由数据段(栈区内存)和代码段(代码区内存)构成. #include "stdafx.h" #include "iostream" using namespace std; class C1 { public: int i; //4 protected: private: }; class C2 { public: public: pro