class SmallInt {
public:
SmallInt(int i = 0): val(i)
{
if (i < 0 || i > 255)
throw std::out_of_range("Bad SmallInt initializer");
}
operator int() const { return val; }
private:
std::size_t val;
};
class SmallInt {
public:
SmallInt(int= 0);
SmallInt(double);
//Usually it is unwise to define conversions to multiple arithmetic types
operatorint() const { return val; }
operatordouble() const { return val; }
private:
std::size_tval;
};
void compute(int);
void fp_compute(double);
void extended_compute(long double);
SmallInt si;
compute(si); // SmallInt::operator int() const
fp_compute(si); // SmallInt::operator double() const
extended_compute(si); // error: ambiguous
void manip(const SmallInt &); double d; int i; long l; manip(d); // ok: use SmallInt(double) to convert theargument manip(i); // ok: use SmallInt(int) to convert theargument manip(l); // error: ambiguous
class Integral;
class SmallInt {
public:
SmallInt(Integral);// convert from Integral to SmallInt
};
class Integral {
public:
operatorSmallInt() const; // convert from Integral to SmallInt
};
void compute(SmallInt);
Integral int_val;
compute(int_val); // error: ambiguous
compute(int_val.operator SmallInt()); // ok: useconversion operator compute(SmallInt(int_val)); // ok: use SmallInt constructor
class SmallInt {
public:
SmallInt(constIntegral&);
};
class SmallInt {
public:
// Usually it is unwise to define conversions tomultiple
arithmetic types
operatorint() const { return val; }
operatordouble() const { return val; }
// ...
private:
std::size_tval;
};
void compute(int);
void compute(double);
void compute(long double);
SmallInt si;
compute(si); // error: ambiguous
class SmallInt {
public:
SmallInt(int= 0);
};
class Integral {
public:
Integral(int= 0);
};
void manip(const Integral&);
void manip(const SmallInt&);
manip(10); // error: ambiguous
manip(SmallInt(10)); // ok: call manip(SmallInt) manip(Integral(10)); // ok: call manip(Integral)
class LongDouble
{
public:
LongDouble(double );
//…
};
void calc( int );
void calc( LongDouble );
double dval;
calc( dval ); // which function
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有