您的位置:首页 > 其它

显式调用构造函数

2016-03-04 21:41 176 查看
#include "stdafx.h"
#include <iostream>
using namespace std;
int i=1;
/*数组构造*/
class testv1
{
public:
int v1;
testv1() {v1=i++;}

};
int _tmain(int argc, _TCHAR* argv[])
{
#define ARRAY_SIZE 10
//testv1 test_array[ARRAY_SIZE];//定义数组时自动调用构造函数,与JAVA不同
testv1 *test_array = new testv1[ARRAY_SIZE]();
for(int i=0;i<ARRAY_SIZE;i++)
{
test_array[i].testv1::testv1();//如果是test_array[i].testv1();编译器会报“error C2274: “函数样式转换”: 位于“.”运算符右边时非法”
cout<< "I am testv   "<<test_array[i].v1<<endl;
}

delete[] test_array;
return 0;
}





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: