继承构造函数只能部分地工作
Inheriting constructors work only partially
我有下面的类,这样写,以便完全工作,无论类型定义是:
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>;
相关文章:
- 有人能解释一下为什么下界是这样工作的吗C++的
- 为什么 HeapFree() 不能正常工作?
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- 我的代码无法正常工作。谁能指出错误?
- 为什么"std::is_function_v"不能按预期工作?
- 为什么在C++中使用关系运算符创建的模板函数不能对字符串正常工作?
- std::remove() 按预期处理文字,但不能与取消引用的迭代器一起工作
- C++自定义删除运算符不能正常工作?
- 为什么使用 exec() 重新启动程序不能正常工作?
- C++:返回本地对象,但不能正常工作
- 有没有办法关闭文件? fclose 不能很好地工作
- 为什么我不能声明一个 constexpr 本地,而一个 const 一个工作?
- ostream_iterator运算符=在pair<int,int>上失败,但在包装器类上工作。我不能为成对<>重载运算符<<吗?
- 为什么带lcov的codecov在Travis上不能正常工作,而在我当地的Linux Mint上却不能正常工作
- 为什么sizeof函数在这里不能正常工作
- 谁能解释一下这个BFS代码是如何工作的?
- 为什么 decltype(declval()<T>.func()) 可以工作,而 decltype(&T::func) 不能工作?
- 静态 constexpr 函数在模板结构中工作,但不能在结构中工作.为什么?
- 为什么这个base64解码/编码功能不能正常工作?