#include<iostream>
using namespace std;
class Test
{
private:
int num;
public:
Test(int a)
{
num = a;
cout << "第" << num << "個Test對象的構造函數調用" << endl;
}
~Test()
{
cout << "第" << num << "個Test對象的析構函數被調用" << endl;
}
};
int main()
{
cout << "進入main()函數" << endl;
Test t[] = {0,1,2,3};
cout << "main()函數在運行中"<< endl;
cout << "退出main()函數" << endl;
return 0;
}
運行結果:
問題:這裏數組作爲一個類對象,把數組裏的值作爲實參每個執行了一下類的操作,這種賦值方法有些奇怪,不太明白是爲什麼?