Avoiding copying variables during initialization in C++ with block -


please code. c++ clang's block feature. can code avoid copying? please let me know opinion. practice of avoiding heap.

class   element {     public:      int value[1024];    //  here large entity.      element()     {     } }; class   world {     public:      element a;     element b;      inline world(element& newa, element& newb)      {           =   newa;   //  source of newa stored in somewhere, copies whole element during assignment.         b   =   newb;     }     inline world(void(^init)(element& a, element& b))      {         init(a, b);     //  assignment done without copying whole element.     } }; 

the way totally avoid copying use pointer or reference. example:

class   world {     public:      element& a;     element& b;      inline world(element& newa, element& newb) : a(newa), b(newb)     {     }      ... }; 

as other reference or pointer, approach requires variables passed not go out of scope.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -