#include<iostream>
using namespace std;
class test
{
public:
int a,b;
test()
{
cout<<"default construictor";
}
test(int x,int y):a(x),b(y){
cout<<"parmetrized constructor";
}
};
int main()
{
test t;
cout<<t.a;
//t=(2,3);->gives error
t={2,3}; //calls paramterized constructor
cout<<t.a;
}
输出: - 默认construictor4196576parmetrized constructor2括号VS大括号
为什么在上面的例子中的情况下,参数的构造函数(即使默认构造函数已经调用。)被称为在{案例},而不是在()
你使用C++ 11吗? – taskinoor