Overloaded operator problem

Started by
2 comments, last by MasterDario 18 years, 1 month ago
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; } }
n/a
Advertisement
Can you paste the declaration of the class please?

Dave
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.
“Always programm as if the person who will be maintaining your program is a violent psychopath that knows where you live”
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.
n/a

This topic is closed to new replies.

Advertisement