Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C++ ambiguous overload for 'operator>>' ?


  • Please log in to reply

#1
Diego8

Diego8

    Member

  • Member
  • PipPipPip
  • 189 posts
I made a class with some functions to handle strings and now i'm trying to implement the method that overloads the input operator (>>) and assigns an input string to an string object.
I think this can be accomplished using the istream& operator>>(istream& entry, string_type& str_type) function (outside the class definition).
My class has two attributes, both of them private: the length of the string and the string created using a pointer to char.
This is my code:

istream& operator>>(istream& entry, string_type& str_type)
{
for (int i=0; i < str_type.GetLength(); i++) // GetLength is public function that returns the Length of the string.
entry >> str_type.GetValue(i); //GetValue is a public function that returns the char in the position i.

return entry;
}

When i try to compile this code i get ambiguous overload for 'operator>>'. ¿¿??

Any help or insight would be greatly apreciated.
  • 0

Advertisements


#2
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
What if I'd tell you that "the class is ok, but the call is bad"?

Edited by IO-error, 19 March 2007 - 02:52 AM.

  • 0

#3
Diego8

Diego8

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 189 posts
Yes that was it. it should be a set function and not a get. Anyway, i decided to use and extra function inside the class. Now it's working.
Thanks.
  • 0

#4
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Your welcome.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP