How to make sure a function is only called once

前端 未结 5 1756
半阙折子戏
半阙折子戏 2021-01-31 17:56

Suppose I have a function named caller, which will call a function named callee:

void caller()
{
    callee();
}  

Now caller might be called m

5条回答
  •  孤街浪徒
    2021-01-31 18:22

    You could use this:

    void caller()
    {
        static class Once { public: Once(){callee();}} Once_;
    }
    

提交回复
热议问题