How to call C++ static method

前端 未结 5 675
萌比男神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:44

    Try this way

    #include 
    using namespace std;
    class MyMath {  
    public:
        static MyMath* calcSomething(void);
    private:
    };
    MyMath* MyMath::calcSomething()
    {
        MyMath *myMathObject=new MyMath;
        return myMathObject;
    }
    int main()
    {   
        MyMath *myMathObject=MyMath::calcSomething();
        /////Object created and returned from static function calcSomeThing   
    }
    

    Thanks

提交回复
热议问题