Should I copy an std::function or can I always take a reference to it?

后端 未结 5 1321
轮回少年
轮回少年 2020-12-01 02:40

In my C++ application (using Visual Studio 2010), I need to store an std::function, like this:

class MyClass
   {
   public:
      typedef std::function

        
5条回答
  •  甜味超标
    2020-12-01 03:12

    I would suggest you to make a copy:

    MyFunction m_myFunction; //prefferd and safe!
    

    It is safe because if the original object goes out of scope destructing itself, the copy will still exist in the class instance.

提交回复
热议问题