假设我有两个类:
// A struct to hold a two-dimensional coordinate.
struct Point
{
float x;
float y;
};
// A struct identical to Point, to demonstrate my problem
struct Location
{
float x;
float y;
};
我想将 a 隐式转换Location
为 a Point
:
Point somePoint;
Location someLocation;
somePoint = someLocation;
所以,我operator
在里面添加了这个Point
:
operator Point(Location &other)
{
// ...
}
g++ 4.9.2
我在 Debian 上编译,并收到此错误:
error: 'Point::operator Point(Location &other)' must take 'void'
听起来编译器希望运算符不接受任何参数,但这似乎不对——除非我错误地使用了运算符。这个错误背后的真正含义是什么?