H*M 发帖数: 1268 | 1 given two classes
class B
{
public:
B(args_1);
B(args_2);
// and many constructors with different arg lists
};
class D : public B
{
public:
D(args_1) : B(args_1) {}
D(args_2) : B(args_2) {}
// and many constructors with different signatures similarly implemented
// some additional stuff specific to D
};
Assume that the arg list for B's constructors are quite long and may be revi
sed pretty often in the future, in which case D's constructors have to be re
coded correspondingly. Duplicating the up |
s******7 发帖数: 386 | |
H*M 发帖数: 1268 | 3 programming版有大牛也说是用template,但是怎么用呢?
【在 s******7 的大作中提到】 : 是不是用template?
|
h*********e 发帖数: 56 | 4 这道题是不是问设计模式啊?
提供一个factory method, which takes arbitrary parameters and returns an
instance of B. Call this method in constructor of D. |
s*****e 发帖数: 60 | 5 Refer to Class Template in http://www.cplusplus.com/doc/tutorial/templates/, it looks similar to the struct solution you thought. |