C++ //练习 14.52 在下面的加法表达式中分别选用了哪个operator+?列出候选函数、可行函数及为每个可行函数的实参执行的类型转换:

C++ Primer(第5版) 练习 14.52

练习 14.52 在下面的加法表达式中分别选用了哪个operator+?列出候选函数、可行函数及为每个可行函数的实参执行的类型转换:

struct LongDouble{
	//用于演示的成员opeartor+;在通常情况下+是个非成员
	LongDouble operator+(const SmallInt&);
	//其他成员与14.9.2节(第521页)一致
};
LongDouble operator+(LongDouble&, double);
SmallInt si;
LongDouble ld;
ld = si + ld;
ld = ld + si;
环境:Linux Ubuntu(云服务器)
工具:vim

 

代码块
struct LongDouble{
	//用于演示的成员opeartor+;在通常情况下+是个非成员
	LongDouble operator+(const SmallInt&);
	//其他成员与14.9.2节(第521页)一致
};
LongDouble operator+(LongDouble&, double);
SmallInt si;
LongDouble ld;
ld = si + ld;
//SmallInt转换为int, LongDouble转换为double或float,double或float转换为int,执行int加法
//Smallint转换为int,int转换为double,LongDouble转换为double,执行double加法
//以上执行都会产生二义性
ld = ld + si;
//LongDouble定义的operator+可以执行相加
//SmallInt内的operator+也可以执行,但需要类型转换
//优先执行第一种

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 08:48:02       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 08:48:02       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 08:48:02       45 阅读
  4. Python语言-面向对象

    2024-07-11 08:48:02       55 阅读

热门阅读

  1. 初识C++

    初识C++

    2024-07-11 08:48:02      15 阅读
  2. 第10章:Electron应用打包与分发

    2024-07-11 08:48:02       13 阅读
  3. PostgreSQL 数据库监控项

    2024-07-11 08:48:02       21 阅读
  4. MYSQl命令总结:1.数据类型、数据库、表、约束

    2024-07-11 08:48:02       21 阅读
  5. 1703:发现它,抓住它

    2024-07-11 08:48:02       17 阅读
  6. 2019年美赛题目Problem A: Game of Ecology

    2024-07-11 08:48:02       19 阅读
  7. 手撸俄罗斯方块(三)——游戏核心模块设计

    2024-07-11 08:48:02       15 阅读
  8. API 类别 - 选择器

    2024-07-11 08:48:02       21 阅读
  9. 画布与印章C++

    2024-07-11 08:48:02       19 阅读