C++: I have a user-defined type whose member function is also a user-defined type. I get compile-time errors when I try to cout that member function. How do I output that member function?
for example: #include "std_lib_facilities.h" struct Instructions { public: Instructions(string i) :instr(i) {} string display() const; string Inst() {return instr;} private: string instr; //MP A.1 }; struct Recipe { public: Recipe (int id, string n, Instructions a) :recipe_id(id), chef_name(n), instr(a) {} string display() const; int Recipe_ID() {return recipe_id;} string Chef_name() {return chef_name;} Instructions Instr() {return instr;} private: int recipe_id; string chef_name; Instructions instr; }; int main() { int rec_id=0; string chef_name=""; string instructions=""; Instructions inst(instructions); Recipe meow(rec_id, chef_name, inst); cout << meow.Instr() << endl; //compile-time error: operator overload }
Join our real-time social learning platform and learn together with your friends!