相关疑难解决方法(0)

转发C++ 0x中的所有构造函数

在C++ 0x中转发所有父构造函数的正确方法是什么?

我一直这样做:

class X: public Super {
    template<typename... Args>
        X(Args&&... args): Super(args...) {}
};
Run Code Online (Sandbox Code Playgroud)

c++ templates constructor c++11

17
推荐指数
2
解决办法
8133
查看次数

为什么所有现有的C++编译器都不支持继承构造函数?

目前,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!!!
};
Run Code Online (Sandbox Code Playgroud)

一个漂亮的代码示例:

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)
Run Code Online (Sandbox Code Playgroud)

c++ inheritance constructor

4
推荐指数
1
解决办法
1593
查看次数

标签 统计

c++ ×2

constructor ×2

c++11 ×1

inheritance ×1

templates ×1