出错:
32 D:\Dev-Cpp\未命名1.cpp
`void operator=(String&, String&)' must be a nonstatic member
47 D:\Dev-Cpp\未命名1.cpp
`void operator=(String&, String&)' must be a nonstatic member作者: 最ヅ后愛上你 时间: 2009-11-4 02:22
opertor=必需是成员函数
以下是MSDN中对此的描述
The assignment operator (=) is, strictly speaking, a binary operator. Its declaration is identical to any other binary operator, with the following exceptions:
●It must be a nonstatic member function. No operator= can be declared as a nonmember function.
●It is not inherited by derived classes.
●A default operator= function can be generated by the compiler for class types if none exists.作者: 风忠人 时间: 2009-11-4 02:22
这题是书上后面的练习题
规定"=,>"运算符重载函数为友元函数,而“+”为运算符重载函数为成员函数
楼上的,可以用中文解释么?我英语太烂了作者: DJ敗類ヤ傲天 时间: 2009-11-4 02:22
严格的说,赋值操作符是一个二元操作符.它的声明和其他的二元操作符一样,但是以下例外
谢谢!你噢作者: 哪里找 时间: 2009-11-4 02:22
你写的那程序也太离谱了吧,,,作者: 魅力ぉ小猪ぎ 时间: 2009-11-4 02:22
楼上的``指教一下啊作者: 依ing梦 时间: 2009-11-4 02:22
友员重载等号的参数要是常类型作者: 落叶秋雨 时间: 2009-11-4 02:22
The assignment operator (=) is, strictly speaking, a binary operator. Its declaration is identical to any other binary operator, with the following exceptions:
●It must be a nonstatic member function. No operator= can be declared as a nonmember function.
●It is not inherited by derived classes.
●A default operator= function can be generated by the compiler for class types if none exists.
这里面清楚的讲到:"No operator= can be declared as a nonmember function",即等于号的重载函数必须是(类)的成员函数。而你的程序里把它作为了友元函数,不符合语法要求。