'std :: ios_base :: ios_base (const std :: ios_base &) is a private error when overloading the << operator for std :: ostram

I have a structure that looks like this:

sturct person
{
    string surname;
    person(string n) : surname(n) {};
}

I need to overload operator<<for std::ostreamand person. I wrote this function:

std::ostream operator<<(std::ostream & s, person & os)
{
    s << os.surname;
    return s;
}

but I get the following errors:

/usr/include/++/4.6/bits/ios_base.h | 788 | error: 'std :: ios_base :: ios_base (const std :: ios_base &) is private |

/usr/include/++/4.6/bits/basic_ios.h | 64 | error: in this context

/usr/include/++/4.6/ostream | 57 | note: the synthesized method 'std :: basic_ios :: basic_ios (const std :: basic_ios &) |

+5
3

std::ostream , , . , , - , .

- :

std::ostream& operator<<(std::ostream& o, const SomeType& t);
+16

:

std::ostream& operator<<(...)
          //^

s, ostream ( private).

+3

:

std::ostream &operator<<(std::ostream & s, person & os)
{
    return s << os.surname;
}
+2

All Articles