Click here to Skip to main content
16,011,374 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: instance by using class name stored in a variable Pin
Cedric Moonen7-Mar-06 20:47
Cedric Moonen7-Mar-06 20:47 
AnswerRe: instance by using class name stored in a variable Pin
toxcct7-Mar-06 21:27
toxcct7-Mar-06 21:27 
GeneralRe: instance by using class name stored in a variable Pin
sunit58-Mar-06 0:34
sunit58-Mar-06 0:34 
GeneralRe: instance by using class name stored in a variable Pin
toxcct8-Mar-06 0:38
toxcct8-Mar-06 0:38 
GeneralRe: instance by using class name stored in a variable Pin
sunit58-Mar-06 2:04
sunit58-Mar-06 2:04 
GeneralRe: instance by using class name stored in a variable Pin
toxcct8-Mar-06 2:09
toxcct8-Mar-06 2:09 
GeneralRe: instance by using class name stored in a variable Pin
sunit58-Mar-06 3:34
sunit58-Mar-06 3:34 
AnswerRe: instance by using class name stored in a variable Pin
Roger Stoltz7-Mar-06 23:31
Roger Stoltz7-Mar-06 23:31 
divine_augustine84 wrote:
i want to create an instance of a class whoes class name is stored in a variable


What does this mean?
My guess is that the problem is that "the class to create is not known at compile time and might be a user provided setting".
If this is the case there is quite an elegant solution for the problem called the "factory design pattern".
Of course this design pattern is completely covered in the book by GoF called Design Patterns[^].
You may also check out this[^] article written by Chris Lasater.

As for how to map the class name to some kind of an ID for which class to create, I have the same suggestion as Cedric: use a map, e.g. std::map.

Hope this helps
--
Roger


It's supposed to be hard, otherwise anybody could do it!
AnswerRe: instance by using class name stored in a variable Pin
jhwurmbach8-Mar-06 3:01
jhwurmbach8-Mar-06 3:01 
QuestionWierd warning Pin
BeakX7-Mar-06 20:37
BeakX7-Mar-06 20:37 
AnswerRe: Wierd warning Pin
Steve Echols7-Mar-06 20:52
Steve Echols7-Mar-06 20:52 
AnswerRe: Wierd warning Pin
sunit57-Mar-06 22:11
sunit57-Mar-06 22:11 
AnswerRe: Wierd warning Pin
Stephen Hewitt7-Mar-06 22:55
Stephen Hewitt7-Mar-06 22:55 
AnswerRe: Wierd warning Pin
David Crow8-Mar-06 2:45
David Crow8-Mar-06 2:45 
QuestionAdding function key to a WIN32 program.. Pin
peter rankel7-Mar-06 20:09
peter rankel7-Mar-06 20:09 
AnswerRe: Adding function key to a WIN32 program.. Pin
Steve Echols7-Mar-06 20:38
Steve Echols7-Mar-06 20:38 
QuestionHow to get the virtual printers (eg: Acrobat PDFWriter) installed? Pin
jahfer7-Mar-06 19:59
jahfer7-Mar-06 19:59 
Questionhow can i use CImageList. Pin
baldha rakesh7-Mar-06 19:53
baldha rakesh7-Mar-06 19:53 
AnswerRe: how can i use CImageList. Pin
Hamid_RT7-Mar-06 20:17
Hamid_RT7-Mar-06 20:17 
Questionappended menuitems disabled Pin
_tasleem7-Mar-06 19:36
_tasleem7-Mar-06 19:36 
AnswerRe: appended menuitems disabled Pin
Cool Ju7-Mar-06 19:55
Cool Ju7-Mar-06 19:55 
GeneralRe: appended menuitems disabled Pin
_tasleem7-Mar-06 20:06
_tasleem7-Mar-06 20:06 
AnswerRe: appended menuitems disabled Pin
Nibu babu thomas7-Mar-06 21:06
Nibu babu thomas7-Mar-06 21:06 
GeneralRe: appended menuitems disabled Pin
_tasleem7-Mar-06 21:41
_tasleem7-Mar-06 21:41 
GeneralRe: appended menuitems disabled Pin
Nibu babu thomas7-Mar-06 22:20
Nibu babu thomas7-Mar-06 22:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.