2 つのクラスがあるとします。
// 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;
};
Location
aを aに暗黙的に変換したいPoint
:
Point somePoint;
Location someLocation;
somePoint = someLocation;
だから、私はこれoperator
を内部に追加しましたPoint
:
operator Point(Location &other)
{
// ...
}
Debian でコンパイルするとg++ 4.9.2
、次のエラーが表示されます。
error: 'Point::operator Point(Location &other)' must take 'void'
コンパイラは演算子が引数を受け入れないようにしているように思えますが、演算子を間違って使用していない限り、それは正しくないようです。このエラーの背後にある本当の意味は何ですか?