I am trying to get a function to be recognized as a friend
but I can not figure out what I am doing wrong. I tried changing things to references and moving things in and out of the namespace and header cpp. There is nothing that I notice as the culprit for why this does not work.
The error I am getting is
error: call to deleted constructor of 'std::__1::ostream' (aka 'basic_ostream<char>')
return output;
^~~~~~
I'm thinking it might be a reference issue, or maybe something I forgot to import when I started. But I can't think of anything.
namespace N
{
class Complex
{
public:
// Contructors
Complex(double n, double i)
{
this->number = n;
this->imaginary = i;
}
Complex()
{
this->number = 0;
this->number = 0;
}
// Accessors
friend ostream operator<< (ostream& os, const Complex& a);
// Operator Overloads
Complex operator + (Complex b)
{
Complex c;
c.number = this->number + b.number;
c.imaginary = this->imaginary + b.imaginary;
return c;
}
private:
double number;
double imaginary;
};
ostream operator<<(ostream& output, const Complex& a)
{
output << fixed << setprecision(1) << a.number << " + " << a.imaginary << "i";
return output;
}
}
Aucun commentaire:
Enregistrer un commentaire