|
![](/i/fill.gif) |
Orchid Win7 v1 <voi### [at] dev null> wrote:
> So I have to put the entire class definition into the header file. But
> that means I have to put Secrets into the header file too - a data
> structure that clients have absolutely no reason to know anything about.
If having the internal-implementation-detail as a member variable of
the class is something you just must avoid, and especially if this is
a class that doesn't get instantiated a lot, then the solution is to
use the Pimpl idiom, which regardless of the funny name, is exactly what
you described. In other words, make a forward declaration of that private
class and just have a pointer to it as member.
> My question is... Is there some simple change I might make to the code
> to avoid all the gotchas of manual memory management?
Yes: Use std::shared_ptr instead of a raw pointer. In other words, you do
it like this:
class PrivateClass;
class MyClass
{
std::shared_ptr<PrivateClass> privateObject;
};
Then in the implementation of MyClass just do a:
privateObject = new PrivateClass;
and then you can forget about managing it yourself.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |