There is a base abstract class and there are two inherited from it. In each inherited class there are declarations of a friendly function which takes the cout object as the first argument, and the second refers to the object itself and this function displays the fields of this class. The problem is that the function can only display fields of the class in which it is declared, and how then can I display the fields of the base class? How is such a problem solved?
here is the base class
class AcctDMA { private: char *label; int rating; protected: char* get_label() { return label; } int get_rating() { return rating; } public: AcctDMA(const char * l = "null", int r = 0); AcctDMA(const AcctDMA &rs); virtual ~AcctDMA() = 0; AcctDMA & operator=(const AcctDMA &rs); friend std::ostream & operator<<(std::ostream & os,const AcctDMA & rs); }; here is an inherited class
class hasDMA : public AcctDMA { private: char *style; public: hasDMA(const char * s = "none", const char *l = "null", int r = 0); hasDMA(const char * s, const AcctDMA &rs); hasDMA(const hasDMA &hs); ~hasDMA(); hasDMA & operator=(const hasDMA &rs); friend std::ostream & operator<<(std::ostream & os, const hasDMA & rs); }; the question was about the last function in the hasDma class
here is its implementation
std::ostream & operator<<(std::ostream & os, const lacksDMA & rs) { os << "color: " << rs.color << std::endl; return os; } I tried to do so, it does not work
std::ostream & operator<<(std::ostream & os, const lacksDMA & rs) { os << AcctDMA::get_label << std::endl; os << AcctDMA::get_rating << std::endl; os << "color: " << rs.color << std::endl; return os; }
hasDMA, and the implementation oflacksDMAis yrHeTaTeJlbrs.get_label()- yrHeTaTeJlbprivatenot available in derived classes.operator<<is friends with the derived class and sees only what the derived class itself sees. To access private fields, use open or protected (in your case) getters - acadeAcctDMA::get_label? Functions in C ++ are called using the()operator. And notAcctDMA::get_label, butrs.get_label(). You need to learn the basics of the language. Also: descriptions in the style "but the compiler swears" are useless here and are not interesting to anyone. Give a detailed description of what the compiler says. - AnT 2:19