关于构造函数的问题
程序代码:
#include <iostream> #include <string> using namespace std; class Teacher { public: Teacher() { director = new char[10]; } char *show(); protected: char *director; //string *director; }; char *Teacher::show() { return director; } class Student { public: Student() { number = 1; score = 100; } void show(); protected: int number; int score; Teacher teacher; }; void Student::show() { cout<<teacher.show()<<endl<<number<<endl<<score<<endl; } void main() { Student a; a.show(); Student b[5]; for(int i=0; i<sizeof(b)/sizeof(Student); i++) { b[i].show(); } cin.get(); }teacher构造函数里面director应该是指向一个内存的首地址,为什么show()函数返回的不是地址呢,