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! ]


|