What's wrong with operator= [closed]

There are quite a few problems, but the one being shown is that your code has

Wektor &operator=(Wektor &wek);

but the operations return a Wektor by value.

The compiler cannot transform a Wektor in a Wektor& because the result is a temporary and the parameter is a non-const reference.

Changing the parameter of assignment to

Wektor &operator=(const Wektor &wek);

will solve this issue (but like said before this code has quite a few other problems).

If you don’t understand why a temporary cannot be converted (bound) to a non-const reference then probably you should read first a bit more about C++ rather that writing code and trying to compile it. Just pick a good book and read it cover-to-cover first, things will be a thousand times easier.

C++ is not a language to learn by experimentation for quite a few reasons, no matter how smart you are (actually being too smart can worsen the situation because sometimes the correct answer is just plain illogical, for historical reasons).

Browse More Popular Posts

Leave a Comment