模板 = 找不到运算符
template = operator not found
我想创建模板运算符=,但它不起作用;
class A
{
public:
template<class T>
A& A::operator=(const T& obj)
{
return *this;
}
};
是的,类为空,但运算符必须使用任何类。
void main()
{
A a;
a = 1.3;
}
但这会产生错误
在类定义中不需要成员函数定义A::
。
class A
{
public:
template<class T>
A& operator=(const T& obj)
{
return *this;
}
};
住
或者,您可以在类定义之外定义它。
class A
{
public:
template<class T>
A& operator=(const T& obj);
};
template<class T>
A& A::operator=(const T& obj)
{
return *this;
}
住
相关文章:
- 为什么 std::variant 找不到运算符<() 当与比较类不在同一命名空间中时
- 为什么 c++ 编译器找不到运算符<<
- 错误 C2679:二进制'<<':找不到采用类型 'overloaded-function' 的右侧操作数的运算符(或者没有可接受的转换)
- 为什么C++找不到布尔运算符,当有一个!范围内的运算符?
- g++ std::set 找不到运算符<为类定义
- 为什么找不到使用命名空间中定义的类型实例化的 std::weak_ptr 的重载运算符==?
- <<找不到运算符,尽管定义了 Foo 类型的右操作数,但该运算符仍采用类型为 Foo 的右侧操作数
- 类没有合适的复制构造函数,找不到二进制运算符 '=',
- 找不到数字文字运算符“运算符”“+BLA”
- 错误:找不到数字文字运算符"运算符 " " U"?
- 模板 = 找不到运算符
- 错误 C2679:二进制'>':找不到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- Arduino IDE告诉我找不到字符串文字运算符“运算符”“DRIVE”
- C++ STL 比较映射找不到(运算符==)
- 错误 C2679:二进制"[":找不到采用右侧操作数的运算符
- 为什么我们在使用宏时找不到合适的运算符重载
- C++ 调试在Visual Studio中找不到'='运算符
- 在自定义双链接列表中的自定义迭代器的取消运算符,找不到二进制操作员
- 错误的任何修复:二进制">>"找不到运算符
- 为什么找不到重载运算符函数?