In brief, my question is about member variables as pointers in unmanaged C++.
In java or c#, we have "advanced pointer". In fact, we can't aware the "pointer" in them. We usually initialize the member of a class like this:
member = new Member();
or
member = null;
But in c++, it becomes more confusing. I have seen many styles: using new
, or leave the member variable in stack.
In my point of view, using boost::shared_ptr
seems friendly, but in boost itself source code there are new
s everywhere. It's the matter of efficiency,isn't it?
Is there a guildline like "try your best to avoid new
" or something?
EDIT
I realize it's not proper to say "leave them in stack", here's a more proper way to say: when i need an object
to be my member variable, should i prefer a object
than a object*
?