【发布时间】:2014-12-09 07:20:25
【问题描述】:
有一个基类:
class A {
public :
A(string a);
void some_method();
};
A 的实现:
A::A(string a) {
cout<<"here it is : "<<a;
}
void A::some_method() { ... }
有一个继承自 A 的类:
class B : A {
public :
B(string b);
void another_method();
};
B 的实现:
B::B(string b):A(string a) // it causes error at compil time
{
cout<<"here it is : "<<b;
}
void B::another_method() { ... }
B的构造函数的实现应该写什么?
【问题讨论】:
-
B::B(string b):A(b).
标签: c++