I am writing a class in which I need to overload the << operator but it keeps giving me a too many parameters for this operator function error. That does not make sense because I am overloading the function so I can make it do whatever I want I would think. I am using a book while learning and they do it the same way so maybe I am just missing something >.< Btw this is just the prototype in the class header.
#include <iostream>
using namespace std;
class morgiana{
int x,y,z;
public:
friend ostream&operator<<(ostream&stream,morgiana obj);
morgiana(int a,int b, int c){x=a; y=b; z=c;}
Hm then why is it restricting access. According to what I just read on friend member functions it should allow you to access private variables. Class header: friend istream &operator>> (istream &, Rational &);
implementation file:
1 2 3 4 5 6 7 8 9 10
istream &operator>>(istream& stream, Rational& obj)
{
cout << "Numerator for first number: ";
stream >> obj.p;
cout << endl;
cout << "Denominator for first number: ";
stream >> obj.q;
cout << endl;
return stream;
}