I'm just breaking into the use of Boost smart pointers for the purpose of making the copying of objects more efficient. Is this possible?
Usually when one makes a copy constructor and assignment operator, they look something like this:
But say you have "shared" smart pointers for your class members? Is it possible to just pass those around, thereby bypassing those expensive copy procedures? How would I set up my class that way? Yes, I am aware that if any instance of aclass writes to what the smart pointers contained, then all instances will change. The classes I want to write will treat these contained instances as read-only after they are created.Code:class aclass { aclass(const aclass &other) { really_expensive_copy_procedure(other); } aclass &operator=(const aclass &other) { really_expensive_copy_procedure(other); return *this; }
The reason I want to do this is I'd like to hide the use of smart pointers from the owners of aclass, thereby making it abstract. That why I'd have members like:
You get the ideaCode:class aclass { aclass foo(); aclass goo(const aclass &aclass_); ... }; ... aclass a_class, anotherclass; aclass yetanotherclass = a_class.foo(); anotherclass.goo(yetanotherclass);



LinkBack URL
About LinkBacks





