4

I have following class, written so, as to work completely, whatever the typedef is:

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();
}

I wanted to make a subclass, that is actually almost the same, apart from overloaded typedef:

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

What I wanted to achieve was to make a class B, that is: - identical to A - has all of As functions (there are few member functions in A, that I've not written) - has all of As operators - has all of As constructors - has different typedef - has the same destructor

My code does not work, because I can't call B(void*, uint32, uint32, size_t), which is what I want. (Intellisense shows me only B() and B(const B&) as available constructors).

4

2 回答 2

4

仅从 VC++2014 CTP 1 起支持继承构造函数。

于 2015-08-18T09:36:30.370 回答
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>;
于 2015-08-18T10:57:25.753 回答