Hi there.
I've built a class that contains an array of characters and implements several methods to manage the array.
I want to redefine operator + so an instruction like b = a + 'x' adds the character 'x' to the array contained in a and puts the result in the array contained in b.
This is what I try:
I've also tried to return a reference to the local object instead of the object itself, but it won't work.Code:// This function is supposed to manage this kind of instructions: // b= a+ 'x' , where a and b are instances of SetOfChar. // Of course, a is referred as 'this' inside the function. SetOfChar SetOfChar::operator+(char c){ // 1) Create a new object with same data than this (a) SetOfChar res(*this); // 2) Add the character res.addChar(c); // 3) RETURN THE RESULT AS AN OBJECT (doesn't work!) return res; }![]()
Both the constructor and the addChar method work properly.
How am I supposed to create an object inside a function and then return it as a result?
Thanks in advance.



LinkBack URL
About LinkBacks



