Sign in to follow this  
zyrolasting

[C++] Pimpl usage

Recommended Posts

Say you have a Pimpl'd class, with a static implementation pointer and reference counter. (All instances of the interface object use the same implementation instance) Does this go by any other name?

Share this post


Link to post
Share on other sites
Oh, shoot. Glad you brought that up. I was thinking about dynamic allocation of the impl class. Don't need that, do I? [smile]

Thanks for the term reference... Couldn't find it on searches.

Share this post


Link to post
Share on other sites
... So you have a pImpl to hide implementation details, of some functionality that only requires one implementation-structure?

You're making it too complicated. Think outside the class.

Just put function descriptions in the header, and implementation, plus file globals that represent the state, in the implementation file. Like they used to do in C. Maybe put it in a namespace or something if you want to keep tidy.

Globals aren't magically "bad". Rather, scoping things more widely than you need to is worse than scoping them exactly as widely as you need to. Data members of a class are scoped more widely than the member functions, so you don't use those (prefer locals to the member functions) when you don't need to (i.e. they don't represent shared state of the object).

Member functions are shared state of a class. Globals are shared state of a module. It's the same thing, really; except that classes are instantiable. If you don't need to instantiate, don't bother.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this