继承构造函数只能部分工作

时间:2015-08-18 09:30:57

标签: c++ c++11 inheritance multiple-constructors inheriting-constructors

无论typedef是什么,我都有下面的类,这样写,完全可以工作:

class A
{
protected:
    typedef uchar mDataType;
    std::vector<mDataType> mData;

    uint32 mWidth;
    uint32 mHeight;

    friend class C;
public:
    A();
    A(void* data, uint32 width, uint32 height, size_t dataSize);
    A(const A& other);
    A(A&& other);
    A& operator=(const A& other);
    A& operator=(A&& other) = delete;

    ~A();
}

除了重载的typedef之外,我想创建一个实际上几乎相同的子类:

class B : public A
{
private:
    typedef float mDataType;
public:
    using A::A;
    using A::operator=;
};

我想要达到的目的是制作一个B级,即:   - 与A相同   - 具有所有As函数(A中的成员函数很少,我没有写过)   - 拥有所有As运营商   - 拥有所有As构造函数   - 有不同的typedef   - 具有相同的析构函数

我的代码不起作用,因为我无法调用B(void *,uint32,uint32,size_t),这就是我想要的。 (Intellisense只显示B()和B(const B&amp;)作为可用的构造函数)。

2 个答案:

答案 0 :(得分:4)

继承构造函数是only supported since VC++2014 CTP 1

答案 1 :(得分:1)

您似乎想要template而不是继承:

template <typename T>
class Mat
{
private:
    using DataType = T;
    std::vector<T> mData;

    uint32 mWidth;
    uint32 mHeight;

    friend class C;
public:
    Mat();
    Mat(void* data, uint32 width, uint32 height, size_t dataSize);
    Mat(const Mat& other);
    Mat(A&& other);
    Mat& operator=(const Mat& other);
    Mat& operator=(Mat&& other) = delete;

    ~Mat();
};


using A = Mat<uchar>;
using B = Mat<float>;