4

タイプ定義が何であれ、完全に機能するように記述された次のクラスがあります。

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&) のみを表示します)。

4

2 に答える 2

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 に答える