0

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. 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.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Robert Lucian Chiriac
  • 686
  • 2
  • 15
  • 24

1 Answers1

2

If it's part of the String class, then it's an assignment of soemthing to this, so it only takes one argument.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
  • 1
    It's part of my String class. I'm trying to do a version of mine. I've tried to do your way, but it gave me an error of memory allocation so I've dumped the idea. – Robert Lucian Chiriac Jul 06 '13 at 21:29
  • 3
    @RobertEagle: When you have errors, you should probably fix them. – David Schwartz Jul 06 '13 at 21:33
  • 1
    @RobertEagle: You probably messed up with your `char` pointers. By "dumping the idea" all you've done is masked the underlying fault, meanwhile restricting yourself to an _incorrect_ and _illegal_ approach that does not compile. – Lightness Races in Orbit Jul 06 '13 at 21:35
  • @RobertEagle I would urge you to figure out what was causing the "error of memory allocation" and fix it. Memory management is an important part of learning how to write C++, and it pays to get good with it early on. – Paul Tomblin Jul 06 '13 at 21:37