Hi, I'm making a simple program in C++.
I have an object named TextReader, with a function GetString(), and I also have another object, TextWriter.
Now when *TextWriter is called, it needs to return a character. It will get this character from TextReader.GetS tring(). However, I get an error C2662 when I try to implement this.
Here is my dereference operator function for TextWriter:
The error I get is "error C2662: 'TextReader.Get String' : cannot convert 'this' pointer from 'const TextReader' to 'TextReader &'".
How do I resolve this error?
I have an object named TextReader, with a function GetString(), and I also have another object, TextWriter.
Now when *TextWriter is called, it needs to return a character. It will get this character from TextReader.GetS tring(). However, I get an error C2662 when I try to implement this.
Here is my dereference operator function for TextWriter:
Code:
char TextWriter::operator*() const
{
string tmpStr;
tmpStr += firstChar; //Convert field firstChar to a 1-char string.
string returnedStr = txtReader.GetString(tmpStr); //Generates error C2662. txtReader is a TextReader object, and a field of TextWriter.
return returnedStr[0];
}
How do I resolve this error?
Comment