简体   繁体   English

函数operator =必须是成员函数

[英]Function operator= must be a member function

I have a function prototype inside a public class access specifier. 我在公共类访问说明符中有一个函数原型。 This is the prototype: 这是原型:

friend void operator=(String &s,char *str);

The String is the class where it's prototyped. String是原型的类。 As you can see it's a friend function. 你可以看到它是一个朋友的功能。 By keeping it this way it gives me this error: 通过这样保持它,它给了我这个错误:

operator =' must be a non-static member // Error: operator= must be a member function

And when I remove the friend property it gives me this error: 当我删除朋友属性时,它给了我这个错误:

error C2804: binary 'operator =' has too many parameters

What's wrong with this prototype? 这个原型出了什么问题? There's no call at operator= function currently, so there shouldn't be any error even without the function definition. 当前没有调用operator = function,所以即使没有函数定义也不应该有任何错误。

如果是String类的一部分,那么它的soemthing到的转让this ,所以只需要一个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM