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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -