繁体   English   中英

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

[英]Inheriting constructors work only partially

无论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运算符 - 全部作为构造函数 - 具有不同的typedef - 具有相同的析构函数

我的代码不起作用,因为我无法调用B(void *,uint32,uint32,size_t),这就是我想要的。 (Intellisense只显示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>;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM