Yes, in C++ this is possible. Probably a factory method design pattern:

Try this : http://gsraj.tripod.com/design/creat...y/factory.html

As for C++ code or Qt code, try Bruce Ekcel's 'Thinking in C++ vol 2'

A free online e-book. Chapter 10: Design patterns - Factories
http://www.mindview.net/Books/TICPP/...ngInCPP2e.html