Using reference as class members for dependencies

后端 未结 7 668
自闭症患者
自闭症患者 2020-12-13 01:06

I am going back to C++ after spending some time in memory-managed languages, and I\'m suddently kinda lost as to what is the best way to implement dependency injection. (I a

7条回答
  •  萌比男神i
    2020-12-13 01:38

    I would steer clear of references as members since they tend to cause no end of headaches if you end up sticking one of your objects in an STL container. I would look into using a combination of boost::shared_ptr for ownership and boost::weak_ptr for dependents.

提交回复
热议问题