c++ - Why does using my print method with std::cout result in an error? -
#include <iostream> using namespace std; class fam { public: char you, urmom, urdad; void addperson(char y, char m, char f) { = y; urmom = m; urdad = f; } }; class tree: public fam { public: void showfamtree() { cout<< "name: " << << endl; cout<< "mother's name: " << urmom <<endl; cout<< "father's name: " << urdad <<endl; } }; int main(void) { tree tree; char a,b,c; cin >> a; cin >> b; cin >> c; tree.addperson(a,b,c); cout<< "family tree: " << tree.showfamtree() <<endl; return 0; }
i wanted print family tree person's name, mother's name, father's name when compile it, following error:
invalid operands binary expression (
basic_ostream<char, std::char_traits<char> >
,void
)
tree.showfamtree()
returns nothing (i.e. void
), doesn't make sense try pass std::cout
. might change
cout<< "family tree: " << tree.showfamtree() <<endl;
to
cout << "family tree: " << endl; tree.showfamtree();
Comments
Post a Comment