又是编译不能通过。。。唉
程序代码:
#include <iostream> #include <cstring> using namespace std; class book{ private: char name[20]; public: const book operator +(const book &a, const book &b) const; void showbookname(); void setname( char *str); char *getname(); book(char *str); }; const book book::operator +(const book &a, const book &b) const{ char str_temp[20]; strcpy(str_temp, (a.getname)); strcat(str_temp, (b.getname)); return book(str_temp); } char* book::getname(){ return name; } void book::setname(char *str){ strcat(name, str); } void book::showbookname(){ cout << name << endl; } book::book(char *str){ strcpy(name, str); } int main(){ book book_one("Hello"); book book_two("yes"); book book_three = book_one + book_two; book book_four = book_one + "Okay!"; book_three.showbookname(); book_four.showbookname(); cout << "Hello world!" << endl; return 0; }