C++ operator overloading

An operator is a symbol that tells the complier to perform specifc mathematical or logical manipulations.

C++ allows u to specify more than one definition for an operator in the same scope, which is called operator overloading.

almost all operators can be overloaded in c++; except below:

1. socpe operator ::

2. sizeof 

3. member selector .

4. member pointer selector *

5. ternary operator ?:

我们期待C3 直接 变成7,9; 但是实际上编译的时候会报错, 因为对于class的对象而言还没有定义+这样的操作

如何定义呢:

这个例子中real 是C1 的;c.real是C2的;

返回一个临时的赋值给C3

C++ operator overloading

 

 C++ operator overloading

C++ operator overloading

 

原文链接: https://www.cnblogs.com/yunpengk/p/13123702.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    C++ operator overloading

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/354960

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 上午8:59
下一篇 2023年3月2日 上午8:59

相关推荐