• Advertisement
Sign in to follow this  

Problem with sub class call

This topic is 3410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem that I can not figure out. I am not sure how to explain this but basically I have a class that has a private member as another class that is already defined and works properly. I want to use ins >> text.value where value is the type of the previously defined class. The previously defined class function that I am trying to use is this:
istream& operator >>(istream& ins, StringVar& the_string)
{
	ins >> the_string.value;
	return ins;
}
The text class has this call:
istream& operator >>(istream& ins, Text& the_text)
{
	ins >> the_text.value;
	return ins;
}
However when I compile I get an error message that says: error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'StringVar *' (or there is no acceptable conversion) I am wondering how to correctly use these class calls. In StringVar class value is char* and in Text class value is StringVar*. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
The operator you're trying to call takes reference to StringVar as parameter. Text::value is StringVar* (pointer). Just as the error describes, you have to dereference the pointer:

istream& operator >>(istream& ins, Text& the_text)
{
assert(the_text.value);
ins >> *the_text.value;
return ins;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement