在下面的类定义中,Exployee类中用了类Name中的对象做为成员,现在我想把Expleyee中的成员内容显示出来,不知道怎么才能做到这点? #include<iostream.h> #include<string.h> #include<math.h> class Name { public: Name(char *pname) { strncpy(name,pname,sizeof(name)); name[sizeof(name)-1]='\0'; } void display() { cout<<name<<endl; } private: char name[20]; }; class Employee { public: Employee(char *pname,char *paddress,int n):name(pname) { strncpy(address,paddress,sizeof(address)); address[sizeof(address)-1]='\0'; number=n;
} void display() { cout<<name.display()<<"\t"<<address<<"\t"<<number; //*显示name,不论是写成cout<<name还是cout<<name.display()都运行出错,不能显示出来name的内容*/ } private: Name name; char address[30]; int number; }; void main() { Employee s("renlin","csu",410083); s.display(); }