same problem - asked differently: polymorphism efficiently

A

alexander.stippler

Hi

I posted a similar question yesterday ("static polymorphism and Factory
pattern"). Now looking at a different aspect:
I have one interface, several implementations. How can I choose one
relization at run-time EFFICIENTLY? So no virtual function calls and no
CRTP (for other reasons). I need just one realization per program run,
but chosen dynamically.

regards,
Alex
 
V

Victor Bazarov

I posted a similar question yesterday ("static polymorphism and
Factory pattern"). Now looking at a different aspect:
I have one interface, several implementations. How can I choose one
relization at run-time EFFICIENTLY? So no virtual function calls and
no CRTP (for other reasons). I need just one realization per program
run, but chosen dynamically.

I think the solution lies beyond the language capabilities. You just
put those implementations each in a different dynamic library and choose
to load the one you need. All exports from it should correspond to the
interface you have implemented.

V
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

I posted a similar question yesterday ("static polymorphism and Factory
pattern"). Now looking at a different aspect:
I have one interface, several implementations. How can I choose one
relization at run-time EFFICIENTLY? So no virtual function calls and no
CRTP (for other reasons). I need just one realization per program run,
but chosen dynamically.

Make the complete program except main and a few helper functions a class
template, explicitly specialize this template for all types you use, select
in main which type you want, instantiate it and use it. If you are worried
about the executable size you can create each explicit specialization in
separate dynamic libraries and link dynamically with it at runtime before
instantiating.

But before doing this, I will consider is this is an EFFICIENT usage of
developper time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top