【发布时间】:2013-03-15 18:20:14
【问题描述】:
我正在研究一个 Vector2D 类,我认为使用 +=/+ 运算符实现向量加法和标量加法都很有意义。
麻烦的是,我真的不知道如何解决这个明显的论点模棱两可,这是 Clang 所说的:
vector2d_test.cpp:17:16: error: use of overloaded operator
'+=' is ambiguous (with operand types 'Vector2D<float>' and 'int')
vector += 1;
~~~~~~ ^ ~~~~~~~
vector2d.hpp:34:18: note: candidate function
Vector2D<T>& operator+=(const Vector2D<T>& other)
^
vector2d.hpp:41:18: note: candidate function
Vector2D<T>& operator+=(const T summand) const
这是两个函数:
Vector2D<T>& operator+=(const Vector2D<T>& other)
{
x += other.x;
y += other.y;
return *this;
}
template <typename S>
Vector2D<T>& operator+=(const S summand) const
{
x += summand;
y += summand;
return *this;
}
所以...知道我能做些什么吗?
【问题讨论】:
标签: c++ operator-overloading vector-graphics