content_views"
class="tags" href="/tags/CLASS.html" title=
class>
class="htmledit_views">
class="tags" href="/tags/CLASS.html" title=class>class="Apple-style-span" style="TEXT-ALIGN: center; WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium 宋体; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">class="tags" href="/tags/CLASS.html" title=class>class="Apple-style-span" style="TEXT-ALIGN: left; LINE-HEIGHT: 22px; FONT-FAMILY: Arial, Helvetica, sans-serif; COLOR: #2e3c78; FONT-SIZE: 14px">
转自:http://linpder.blog.163.com/blog/static/487641020095231925257/
运算符在重载的时候有两种方式c;一是成员函数方式c;二是成友元(friend)函数方式。class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
成员函数比较简单。下面是一个示例代码:class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
如果是设置成友元函数c;一定要注意:class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
color: #0000ff;">(1)当重载友元函数时c;将没有隐含的参数this指针。这样c;对双目运算符c;友元函数有2个参数c;对单目运算符c;友元函数有一个参数。class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
(2)有些运行符不能重载为友元函数c;它们是:color: #ff8040;">=,(),[]和->。class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
因此c;上面那个+运算符如果是重载为友元函数的话c;应该写成:class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
还需要注意一点c;有的VC 6.0class="tags" href="/tags/BianYiQi.html" title=编译器>编译器在编译上面代码的时候会报错c;错误为:class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
color: #ff0000;">fatal error C1001: INTERNAL COMPILER ERRORclass="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
原因是VCclass="tags" href="/tags/BianYiQi.html" title=编译器>编译器本身的问题。class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
解决办法:class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space"> 在类的声明之前再加上一个声明。具体代码如下:class="tags" href="/tags/CLASS.html" title=class>class="Apple-converted-space">
这样就没有问题了。