For now, both of G++ and VC++ 2010 don't support inheriting constructors.
However, I think this is one the most beautiful features in C++0x. And I think it should be rather easy to implement by the compiler.
Why are the compilers not interested of this feature?
Assume I want to design my own string class by inheriting std::string like this:
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!!!
};
A beautiful code example:
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)
There's a lot of new material in C++0x, and it seems that the volunteers working on gcc found other changes more interesting to work on first.
As for VC++, there's not only the prioritization of work, but the additional costs (often mentioned on Microsoft product manager blogs) of requirements, documentation, and very extensive testing, which are necessary parts of a product that is sold, above and beyond just making it work.
Finally, it sounds like there was recent discussion among the C++0x committee about cutting this feature, since something like 95% of use cases have straightforward workarounds.
Combined, I'm not surprised that the compiler engineers are saving this one for later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With