c++ - Avoid copying complex data in class constructor -
lets have class, , 1 of member variables complex class. want avoid creating copy of complex class, want use in class. whats best way organize myclass?
at moment have this:
class myclass { public: myclass(const complexclass& complex_class) : m_class(complex_class) {} private: const complexclass& m_class; // best practice here? };
can this? or maybe m_class should pointer? or in situation?
if can guarantee passed reference valid during object lifetime solution enough.
if not recommend using smart pointer e.g. shared_ptr extend lifetime of passed data.
(note not have reorganize class declaration of complex_class
object)
Comments
Post a Comment