yungman
- 5,741
- 294
Filip Larsen said:You are getting the error in line 40 because that friend function is not a member function, but more like a static function, and for those there are nothis
defined. Defining a friend function textually inside a class definition does no in itself mean its a member function; it means just the same as if the friend function was defined outside the lexical scope of the class. Also, contrast this with the member function you define in line 30 which do have athis
defined, soname
there implicitly refers tothis->name
.
As a minimal fix closest to your original intent I will suggest you just userhs.name
in line 40, or, since you overwritemul2.name
withMulti2
on the next line anyway, just useMulti2
in line 40 and skip the string copy. But if you get into more trouble fumbling around with those damn c-string you know what I am going to say.
I know you are right, I even try putting vec3 D(name, 0, 0, 0); inside main, it won't work. I tried using this->x inside the friend function and it doesn't work. So definitely what you said is true.
BUT I declare mul2 as object of Complex. Does it matter whether it's a member function or only a friend? I should be able to use the public member name[Nsize] for mul2. I still don't quite get what the reason.
Thanks
Last edited: