class example
{
private:
int i1, i2;
}
example e1, e2, e3;
//filling e1, e2 with content
e3 = e1 * (-e2)
class example
{
private:
int i1, i2;
}
example e1, e2, e3;
//filling e1, e2 with content
e3 = e1 * (-e2)
class example{ int i1, i2;public: example(int i = 0, int j = 0) : i1(i), i2(j) {} example operator * (const example& e) const { return example(i1 * e.i1, i2 * e.i2); } example operator - () const { return example(-i1, -i2); }};
example example::operator -(const example &rhs){ return(example((i1 - rhs.i1), (i2 - rhs.i2)));} // end -
quote:Original post by YoshiN
Notice that there aren''t any parameters for the - operator that was overloaded. If you wanted to do e1 - e2, then you would overload the - operator again, with an example as a parameter.
example example::operator -(const example &rhs){ return(example((i1 - rhs.i1), (i2 - rhs.i2)));} // end -