说明下面两个类型转换运算符的区别
class A{
operator const int();
operator int() const;
};

注意一点,转换到的类型不能是void类型和数组类型,因为作为函数的返回值的类型不能是数组
转换函数跟构造函数是相反的,构造函数只用于从某种类型到类类型的转换。
所以上面的题目
operator const int();
将A的类型转换为 const int 类型
operator int() const;
将A的类型转换为int 类型,但是不希望你通过转换函数修改类的对象

博客主要讲解了C++中两个类型转换运算符的区别,即`operator const int();`和`operator int() const;`,前者将A类型转换为const int类型,后者将A类型转换为int类型且不希望通过转换函数修改类对象,还提到转换到的类型不能是void和数组类型。

被折叠的 条评论
为什么被折叠?



