std :: vector <>使用基类的构造函数并重载派生类后,不存在默认构造函数

时间:2018-07-19 17:49:40

标签: c++ templates inheritance visual-c++ constructor

我正在创建一个模板类并继承std :: vector。与std::vector的所有构造函数一起,我想用自定义类重载派生类的构造函数。但是,当我这样做时,会收到默认构造函数调用的编译错误。

以下代码:

template<typename T, unsigned int N>
class _std_vector : public std::vector<T>
{
    public:
        using std::vector<T>::vector;
        _std_vector(const MyCustomClass& that)
        {
            //Do Something
        }
}

我打电话如下:

MyCustomClass my;
_std_vector<int, 8> sv{ my};

当我重载构造函数时,上面的方法就很好了。但是,默认的非参数化构造函数会产生编译错误。

  

错误C2512'_std_vector ':没有适当的默认构造函数   可用

_std_vector <int, 8> svv; //This works fine until I add _std_vector(const MyCustomClass& that)

但是请注意,std::vector的所有其他参数化构造函数似乎都可以编译。

我在这里想念东西吗?

0 个答案:

没有答案
相关问题