Friend methods in C++ is not working

后端 未结 2 1590
借酒劲吻你
借酒劲吻你 2021-01-28 12:17

I wrote the following code:

class Osoba{
private:
    string imie, nazwisko, kolorOczu;
    friend void Dziecko::coutall();
public:
    Osoba(string imie, string         


        
2条回答
  •  悲&欢浪女
    2021-01-28 12:59

    It seems you can't call that method because it uses private members of class Osoba.

    Try using the imie as a protected variable instead of private.

    Here is a short explenation.

    The 2 options available are:

    1) friend the entire class, not a good practice when using inheritance.

    2) Use protected members. this is the best way to access private members on inheritance.

提交回复
热议问题