In C ++ 1y, you can do this:
class AAA { public: static auto make() { return AAA(); } }; int main() { AAA aaa = AAA::make(); }
This is not legal in C ++ 11, since you need to specify the return type for make() . In C ++ 98/03/11 you can:
class AAA { public: typedef AAA Self; static Self make() { return AAA(); } };
It is low-tech, but very readable.
<aside>
You should avoid returning const-qual values โโby value. This prevents efficient semantics of movement. If you want to not assign r values, then create an assignment statement qualified with & .
</aside>
source share