是否可以像在 Java 中一样从 C++ 中的静态方法返回对象?我正在这样做:
class MyMath {
public:
static MyObject calcSomething(void);
private:
};
我想这样做:
int main() {
MyObject o = MyMath.calcSomething(); // error happens here
}
MyMath 类中只有静态方法,因此实例化它没有意义。但我得到这个编译错误:
MyMath.cpp:69:错误:“。”之前的预期主表达式 令牌
我究竟做错了什么?我必须实例化 MyMath 吗?如果可能的话,我宁愿不这样做。