目前,G++和VC++ 2010都不支持继承构造函数。
然而,我认为这是C++0x中最美妙的特性之一。我认为编译器实现这个特性应该相对容易。
为什么编译器对这个特性不感兴趣呢?
假设我想通过继承std::string来设计自己的字符串类,就像这样:
class MyString : public std::string
{
public:
// I have to redefine many overloaded ctors here and forward their arguments to
// std::string's ctors. How tedious it will be!!!
};
一个漂亮的代码示例:
struct B1
{
B1(char);
};
struct B2
{
B2(double);
B2(int);
};
struct D1 : B1, B2
{
using B1::B1; // D1(char)
using B2::B2; // D1(double), D1(int)
};
D1 d('c'); //OK, invokes D1(char)
std::string
不应该被派生(或者其他任何STL容器)。 - fredoverflow