How to return self static object from class constructor in C++

1 Answer

0 votes
#include <iostream>

class Example {
public:
    float x, y, z;
    
    static Example& Get() {
        static Example ex;
        
        return ex;
    }
    
    void Print() {
        std::cout << "Example";
    }
};
    
int main() {
    Example::Get().Print();
}




/*
run:

Example

*/

 



answered Feb 6, 2023 by avibootz

Related questions

1 answer 210 views
1 answer 197 views
1 answer 98 views
1 answer 185 views
1 answer 183 views
1 answer 160 views
...