Skip to content

课后练习14.52 LongDouble转SmallInt的方式 #87

@EnzoFerrari430

Description

@EnzoFerrari430

ld = si + ld;
我看很多人都说只能转换成内置类型进行相加operator+(int,float)或者operator+(int,double)
为什么下面这种不行呢
friend SmallInt operator+(const SmallInt &,const SmallInt &);
ld可以先转换成float或者double然后再转换成int。SmallInt可以调用SmallInt(int = 0); 构造一个临时对象
然后得到SmallInt再转换成int类型,再转换成double最后调用LongDouble(double = 0.0);构造一个临时对象。这种方式不行吗?虽然也会产生二义性。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions