1 class base 2 { 3 public: 4 base(string szNm) : basename(szNm) {} 5 string name() {return basename;} 6 virtual void print(ostream &os) {os << basename;} 7 private: 8 string basename; 9 } 10 11 12 class derived : base 13 { 14 public: 15 derived(string szNm, int ival): 16 base(szNm), 17 mem(ival) {} 18 void print() 19 { 20 print(base::ostream &os); // 答案是这个 21 base::rint(ostream &os); // 我觉得是这个 22 os < "--" << mem; 23 } 24 private: 25 int mem; 26 }