请考虑以下代码:
#include <iostream>
class Point
{
public:
int x,y;
Point(int newx, int newy) : x(newx), y(newy) {}
};
Point operator"" x(const unsigned long long i)
{
return Point(i, 0);
}
int main()
{
Point p = 5x;
std::cout << "\npoint is " << p.x << "," << p.y << "\n\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
UDL有效,但它是否可以使它适用于Point的构造函数的两个参数?例如,3x5是一个文字,Point(3,5)甚至是偶数3.5x,然后在操作员体中做一些数学运算,将整个部分与浮点数的小数部分分开..?