smart pointers + “this” considered harmful?

后端 未结 8 1984
情书的邮戳
情书的邮戳 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:23

    One example of correct use is return *this; in functions like operator++() and operator<<().

    0 讨论(0)
  • 2020-12-14 12:36

    If you need to use this, just use it explicitly. Smart pointers wrap only pointers of the objects they own - either exclusivelly (unique_ptr) or in a shared manner (shared_ptr).

    0 讨论(0)
提交回复
热议问题