抽象模板类和继承构造函数
Abstract template class and inheritance contructor
我有构造函数的问题,我想做这样的事情:
A<int>* first = new B<int>
A<int> *second;
second= new B<int>(*A);
我已经尝试在参数列表中使用指针,引用和值,没有任何工作,我不知道为什么。这是我的不工作的构造函数:
template <class T>
B<T>::B(B<T> other)
它与const A<T>&
工作,谢谢,还有一件事,如果可以的话。我必须在这个构造函数中访问B类私有类字段。如果只有A类。我能改天再做吗?
假设B<T>
继承了A<T>
,正如您在评论中所描述的,当您编写new B<int>( some_value_of_type_A );
必须提供一个A<T>
类型的构造函数,如下所示:
template<class T>
B<T>::B(const A<T>& other);
相关文章:
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 如果我真的真的想从 STL 容器继承,并且我继承构造函数并删除新运算符,会发生什么?
- C++继承:构造函数中的字符串构造
- 继承构造函数和其他变量的解决方法
- 带有此指针的模板类多重继承构造函数不起作用?
- 虚拟继承构造函数的组装
- C++继承构造函数的可见性
- 继承构造函数(ISO 2011 SEC 12.9第7段)
- 没有C 11的继承构造函数
- 使用关键字继承构造函数时出乎意料的行为
- 继承构造函数不允许类似数组的初始化
- 从基于QObject的类继承构造函数
- 继承构造函数并提供新的重载:无参数基构造函数似乎不参与重载解析
- C++多继承构造函数
- 具有独占继承构造函数的类的值初始化
- C++ 继承构造函数重写
- 继承构造函数与转发
- 默认情况下继承构造函数 noexcept(true)
- 有没有办法在继承构造函数时访问初始值设定项列表
- 从 std::function 继承构造函数时"function returning a function"