转换运算符

1、当要将对象进行强制类型转换时需要重载转换运算符()

2、实现:RMB->double

operator double() // double 就是返回类型,不需要在函数前额外声明
{
	return x / 100.0; // 一定要有.0, 否则还是返回整型
}

3、与转换构造函数互逆:double->RMB

RMB(double x_val)
{
	x = x_val;
}

猜你喜欢

转载自blog.csdn.net/Littlsecr/article/details/80724123