How to call C++ static method

前端 未结 5 687
萌比男神i
萌比男神i 2020-12-30 21:15

Is it possible to return an object from a static method in C++ like there is in Java? I am doing this:

class MyMath {
    public:
       static MyObject calc         


        
5条回答
  •  灰色年华
    2020-12-30 21:42

    What am I doing wrong?

    You are simply using incorrect syntax... the :: operator (scope resolution operator) is how you would access classes or members in different namespaces:

    int main() { 
        MyObject o = MyMath::calcSomething(); // correct syntax
    }
    

    Do I have to instantiate MyMath?

    No.

提交回复
热议问题