Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Differentia...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 9 Topic 9505 of 9807
Post > Topic >>

Re: Differentiating pimpl idiom cl***** in c++

by Tony Delroy <tony_in_da_uk@[EMAIL PROTECTED] > Apr 17, 2008 at 03:55 AM

On Apr 17, 2:36 am, Fejimush <grahamre...@[EMAIL PROTECTED]
> wrote:
> What are good strategies for selecting, either at run-time or compile
> time, various pimpl'ed implementations?  Also, retaining the ability
> to switch implementations without recompiling.
>
> Boost has an example but with only one implementation class:  (what
> would an example with 2 implementation cl***** look
like?)http://www.boost.org/doc/libs/1_35_0/libs/smart_ptr/sp_techniques.htm...
>
> The pimpl'ed class cpp file has to include at least one implementation
> header file.  Is there a method to avoid changing that included header
> when switching implementations?
>
> Or, are we using the pimpl idiom incorrectly?

Hi Graham,

I think you're a little confused about the pimpl idiom.  Its purpose
is to allow users of a class to know that the class will contain space
for a pointer to an implementation class, without having to know
anything about the contents of the implementation class.  This allows
the implementation data to be varied without requiring recompilation
of the clients.  It is not intended as a method for switching between
concurrently maintained implementations - rather it allows one
implementation to be maintained (i.e. updated) while limiting the
recompilation needed.

To switch between multiple implementations of a class, you can employ
other techniques: e.g. run-time polymorphism (virtual dispatch),
pointers to functions, the humble if statement etc; or compile time
#ifdefs (change via compiler switch), templates, typedefs (facilitate
centralised choice between implementations, i.e. one line code
changes)....  As run-time switching is the more general of your
requests (compile time is simply a performance improvement thereto) I
suggest you start by read ing about the "virtual" keyword and OO
techniques.

Cheers,

Tony

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 9 Posts in Topic:
Differentiating pimpl idiom classes in c++
Fejimush <grahamreitz@  2008-04-16 11:36:38 
Re: Differentiating pimpl idiom classes in c++
Tony Delroy <tony_in_d  2008-04-17 03:55:28 
Re: Differentiating pimpl idiom classes in c++
Carl Barron <cbarron41  2008-04-17 04:13:14 
Re: Differentiating pimpl idiom classes in c++
Fejimush <grahamreitz@  2008-04-17 12:03:38 
Re: Differentiating pimpl idiom classes in c++
Carl Barron <cbarron41  2008-04-17 19:35:32 
Re: Differentiating pimpl idiom classes in c++
Tony Delroy <tony_in_d  2008-04-18 06:13:17 
Re: Differentiating pimpl idiom classes in c++
Fejimush <grahamreitz@  2008-04-19 02:01:53 
Re: Differentiating pimpl idiom classes in c++
Tony Delroy <tony_in_d  2008-04-20 21:04:20 
Re: Differentiating pimpl idiom classes in c++
marlow.andrew@[EMAIL PROT  2008-04-21 20:28:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 19 19:47:11 CDT 2008.