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

Inheriting constructors work only partially

本文关键字:工作 能部 构造函数 继承      更新时间:2023-10-16

我有下面的类,这样写,以便完全工作,无论类型定义是:

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,我没有写)-有所有的a算子-拥有所有的As构造函数-有不同的类型定义-有相同的析构函数

我的代码不工作,因为我不能调用B(void*, uint32, uint32, size_t),这是我想要的。(智能感知只显示B()和B(const B&)作为可用的构造函数)。

继承构造函数仅从vc++ 2014 CTP 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>;