我想知道是否有可能创建返回 ostream 某些部分的函数,例如:
#include <iostream>
class Point {
public:
Point(int x, int y){
this->x = x;
this->y = y;
}
?? getXY(){ // I wish this function returned ostream
return ??;
}
private:
int x,y;
};
int main() {
Point P(12,7);
std::cout << "(x,y) = " << P.getXY(); // (12, 7);
}
Run Code Online (Sandbox Code Playgroud)
我希望输出是:
(x,y) = (12,7)
Run Code Online (Sandbox Code Playgroud)
我不希望 getXY() 返回任何字符串或字符数组。我可以以某种方式返回流的一部分吗?