Sign in to follow this  
toogreat4u

Problem with sub class call

Recommended Posts

toogreat4u    127
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
Ftn    462
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this