模板类赋值操作符类
Template class assignment operator class
本文关键字:赋值操作符 更新时间:2023-10-16
我有一个TemplateArray和CharArray类。
我如何使templatearray的赋值操作符仅从chararray类复制时,templatearray是相同类型(即char)或类似类型(即unsigned char)的chararray?
TemplateArray和CharArray在功能上是相同的(除了CharArray可以处理以NULL结尾的字符串)。
例如:template<typename TemplateItem>
TemplateList & TemplateList<TemplateItem>::operator=(const CharArray &ItemCopy)
{
//How do I only copy when TemplateList is of type char (or similar unsigned char)
//IE is same/similar to CharArray
//Both classes are functionally the same, except CharArray is chars only
}
看起来您需要TemplateList::operator=
的专门化:
template<>
TemplateList& TemplateList<char>::operator=(const CharArray &ItemCopy)
{
// Do the copying here, you don't provide enough
// information for a practical suggestion
}
相关文章:
- c++中的重载赋值操作符
- c++类继承和赋值操作符
- 带引用类成员的赋值操作符
- 复制构造函数,赋值操作符重载
- c++派生类赋值操作符
- 通过调用Move赋值操作符实现Move构造函数
- 带有映射的赋值操作符
- 单参数构造函数和赋值操作符
- 如何从复制赋值操作符调用复制构造函数
- c++复制构造函数,重载赋值操作符,方法get()
- 用于具有const数据成员的类的move和右值赋值操作符
- 类赋值操作符和复制构造函数
- 赋值操作符重载
- 影响正确性的move构造函数/赋值操作符示例
- 当类是子类时重载赋值操作符
- 如果没有定义Move语义(Move构造函数和Move赋值操作符),编译器是否默认优化
- 在类赋值操作符函数中,为什么必须返回*this ?
- 模板类的重载赋值操作符
- 使用重载赋值操作符
- 类和向量的重载赋值操作符