转换构造函数不接受支撑列表

时间:2018-05-11 23:40:03

标签: c++ constructor braces list-initialization

所以当我搞乱构造函数时,我制作了这段代码:

class super
{
public:
int duper, duperer;

friend ostream& operator << (ostream&, super&);
friend super operator+ (super& uno, super& dos);
friend int main();
super() {};
super(int);
super(int, int);
};

ostream& operator << (ostream& out, super& Sout)
{
    cout << "The " << Sout.duper << " and the " << Sout.duperer << " are super!" << endl;
    return out;
}

super operator+ (super& uno, super& dos)
{
    return { uno.duper + dos.duper , uno.duperer + dos.duperer };
}


super::super(int duper) : duper(duper) {};
super::super(int dupster, int pupster) : duper(pupster), duperer(dupster)     {};

int main()
{

super Supper = { -1, 0 }, Copper(1, 1);
Supper = super(3, 3) + Copper;
cout << Supper << "!!!\n";
}

一切正常,初始化列表每次都转换为我的类型的对象。但是,当我这样做时(更改主要支撑列表的构造函数):

class super
{
public:
int duper, duperer;

friend ostream& operator << (ostream&, super&);
friend super operator+ (super& uno, super& dos);
friend int main();
super() {};
super(int);
super(int, int);
};

ostream& operator << (ostream& out, super& Sout)
{
    cout << "The " << Sout.duper << " and the " << Sout.duperer << " are super!" << endl;
    return out;
}

super operator+ (super& uno, super& dos)
{
    return { uno.duper + dos.duper , uno.duperer + dos.duperer };
}


super::super(int duper) : duper(duper) {};
super::super(int dupster, int pupster) : duper(pupster), duperer(dupster)     {};

int main()
{

super Supper = { -1, 0 }, Copper(1, 1);
Supper = {3, 3} + Copper;
cout << Supper << "!!!\n";
}

......代码没有编译。这次为什么没有支撑列表转换为对象?

非常感谢,请不要对我在这里使用的名字感到生气。我只是想确保一切都让人感到困惑。

0 个答案:

没有答案