c++ - 我如何重载C++中的赋值运算符

标签 c++ operator-overloading performance effect primitive-types

我一直在阅读这篇文章:https://www.thc.org/root/phun/unmaintain.html ,并且我一直在尝试实现步骤 Misleading names(搜索 isValid(x))和 How To Fix Unused Variable Errors(#29 under杂项技术)。

我希望做一些更有用的事情,(也是根据文章)因为在更少的行上做更多的事情更好。

不幸的是,我不知道如何重载基本类型的赋值运算符。我知道如果我使用的是类,我可以做类似 operator=(&Other o) 的事情,但遗憾的是,C/C++ 并没有通过为某些基本类型提供类来取代 Java...

最佳答案

Unfortunately, I have no idea on how to overload the assignment operator for a basic type. I know I could do something like operator=(&Other o) if I was using a class

您不能为 C++ 中的内置类型重载运算符。故事到此结束。

but alas, C/C++ doesn't take after Java by having classes for some basic types...

...你说得好像 Java 对 intInteger 的区分在某种程度上是件好事:)

关于c++ - 我如何重载C++中的赋值运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23853576/

相关文章:

c++ - 重载运算符有什么问题?

c++ - 运算符重载问题

java - Tomcat 在一台普通服务器上每秒可以处理多少个请求?

c++ - 从 QML 文件中包含另一个 QML 文件

c++ - Google Protocol Buffers,在提供的流对象中向后重新定位 IO 头

c++ - 错误 : address of overloaded function with no contextual type information

python - 封装严重损害性能?

java - 使用巨大的 map (putIfAbsent)

c++ - 在 C++ 中打开和显示图像?

c++ - 转换为使用 typedef 创建的结构类型