构造函数
#include<iostream.h>int i=0;
class A {
public:
A(){i++;}
};
void main()
{A a,b[3],*c;
c=b;
cout<<i<<endl;
}
i为多少?为什么不是3,而是4呢?
#include<iostream> using namespace std; int i=0; class A { public: A(){i++;} }; int main() { cout << "Before definition of 'a' : " << i << endl; A a; // 第一次 cout << "Before definition of 'b' : " << i << endl; A b[3]; // 第二次,第三次和第四次 cout << "Before definition of 'c' : " << i << endl; A *c; c = b; cout << "Last : " << i << endl; }