在Java中,您只需return this获取当前对象即可.你是如何用C++做到的?
Java的:
class MyClass {
MyClass example() {
return this;
}
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
构造函数中的c ++调用构造函数
如何在c ++中做"自我"(这个)作业?
Java的:
public Point(Point p) {
this(p.x, p.y);
}
Run Code Online (Sandbox Code Playgroud)
在C++中如何做到这一点?
它会是相似的this->(constructor of point that takes x, constructor of point that takes y);吗?