Jump to content
  • Advertisement
Sign in to follow this  
MasterDario

Overloaded operator problem

This topic is 4479 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

Hey all, in my class i overloaded the >> operator so that i can use cin on an object of a class. ex: Money MyMoney cin >> MyMoney I've got this working fine in int main(), but for some reason when i try to to put that into a function, it doesnt work. Its returning error: C2676 Money does not define this operator or a convertion acceptable to the predefined operator. Heres my function. Im thinking that maybe i'm passing in the function parameters incorrectly. // Reads in Money from Input File and stores in array of Money Objects void ReadInMoney(istream& in,Money& Arr,int Counter) { for(int i=0; i < Counter; ++i) { in >> Arr; } }

Share this post


Link to post
Share on other sites
Advertisement
Hi,

in the code you poste Arr is a reference and not an arry, but you use it like one. So the problem seams not to be your overloading, but your use of references and arrays.

void ReadInMoney(istream& in, Money* Arr, int Counter)
{
for(int i=0; i < Counter; ++i)
{
in >> Arr;
}
}

this should work.

Share this post


Link to post
Share on other sites
Actually, I just fixed the problem. I forgot that when passing in an array that you have to put the name followed by [].

One thing I find interesting that i completely forgot about is that arrays are automatically passed by reference. Since i completely forgot that, it was causing me some problems, but everything seems to be running okay now.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!