smart pointers + “this” considered harmful?

后端 未结 8 2003
情书的邮戳
情书的邮戳 2020-12-14 12:10

In a C++ project that uses smart pointers, such as boost::shared_ptr, what is a good design philosophy regarding use of \"this\"?<

8条回答
  •  孤城傲影
    2020-12-14 12:12

    Another reason to pass around this is if you want to keep a central registry of all of the objects. In the constructor, an object calls a static method of the registry with this. Its useful for various publish/subscribe mechanisms, or when you don't want the registry to need knowledge of what objects/classes are in the system.

提交回复
热议问题