Jump to content
  • Advertisement
Sign in to follow this  
zyrolasting

[C++] Pimpl usage

This topic is 3057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
What is your intended use case? Any form of implicit shared state should be very carefully managed.

Share this post


Link to post
Share on other sites
Application timer. The user is not in a position to accidentally cause damage. I do not use threads, either. (I've haven't used them at all, yet.)

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!