Click here to Skip to main content
15,915,702 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Swap Bytes Pin
Christian Graus1-Feb-07 23:31
protectorChristian Graus1-Feb-07 23:31 
GeneralRe: Swap Bytes Pin
Aint2-Feb-07 2:00
Aint2-Feb-07 2:00 
GeneralRe: Swap Bytes Pin
Michael Dunn2-Feb-07 9:12
sitebuilderMichael Dunn2-Feb-07 9:12 
GeneralRe: Swap Bytes Pin
Christian Graus2-Feb-07 10:21
protectorChristian Graus2-Feb-07 10:21 
QuestionLoad a class depending on a string Pin
S.C.Wong1-Feb-07 22:57
S.C.Wong1-Feb-07 22:57 
AnswerRe: Load a class depending on a string Pin
Waldermort1-Feb-07 23:21
Waldermort1-Feb-07 23:21 
QuestionRe: Load a class depending on a string Pin
David Crow2-Feb-07 2:46
David Crow2-Feb-07 2:46 
AnswerRe: Load a class depending on a string Pin
jhwurmbach2-Feb-07 3:05
jhwurmbach2-Feb-07 3:05 
S.C.Wong wrote:
Something like:

if (strKey == "cat") m_pPet = new CCat();
else if (strKey == "dog") m_pPet = new CDog();
else if (strKey == "monkey") m_pPet = new CMonkey();
...


Personally, I would put this into a PetFactory-Class, which has a static method
Pet* CreatePet( const std::string& PetType);
With basically your logic inside.

Your call would look like this:
PetFactory factory;
m_pPet = factory.CreatePet( "cat");

Maybe the Petfactory would be a singelton or a member.

This way, You may later change the way the connection string<->pet-derived class is done. Maybe you want it configurable by a file?
Simply give the file to the PetFactory, change the PetFactory internals to build a map string<->c'tor and youre done.


"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."

-- Caius Petronius, Roman Consul, 66 A.D.
m_PetFactory
AnswerRe: Load a class depending on a string Pin
Cedric Moonen2-Feb-07 4:10
Cedric Moonen2-Feb-07 4:10 
GeneralRe: Load a class depending on a string Pin
Mark Salsbery2-Feb-07 5:53
Mark Salsbery2-Feb-07 5:53 
GeneralRe: Load a class depending on a string Pin
Cedric Moonen2-Feb-07 6:28
Cedric Moonen2-Feb-07 6:28 
GeneralRe: Load a class depending on a string Pin
Mark Salsbery2-Feb-07 7:11
Mark Salsbery2-Feb-07 7:11 
QuestionConvert LPWSTR to LPSTR Pin
ajitatif angajetor1-Feb-07 22:39
ajitatif angajetor1-Feb-07 22:39 
AnswerRe: Convert LPWSTR to LPSTR Pin
jhwurmbach1-Feb-07 22:46
jhwurmbach1-Feb-07 22:46 
QuestionCan load custom control with dll resource Pin
dungpapai1-Feb-07 22:36
dungpapai1-Feb-07 22:36 
Questionavailable characters Pin
vlad.gs1-Feb-07 22:19
vlad.gs1-Feb-07 22:19 
AnswerRe: available characters Pin
Naveen2-Feb-07 1:02
Naveen2-Feb-07 1:02 
GeneralRe: available characters Pin
vlad.gs2-Feb-07 1:44
vlad.gs2-Feb-07 1:44 
GeneralRe: available characters Pin
Hamid_RT14-Feb-07 6:15
Hamid_RT14-Feb-07 6:15 
AnswerRe: available characters Pin
Mark Salsbery2-Feb-07 6:41
Mark Salsbery2-Feb-07 6:41 
AnswerRe: available characters Pin
Mark Salsbery2-Feb-07 7:12
Mark Salsbery2-Feb-07 7:12 
Questioncan't get the updated data during Win32 Release Pin
MrKyaw1-Feb-07 22:11
MrKyaw1-Feb-07 22:11 
QuestionConversion Hex string to ASCII value Pin
Ram Murali1-Feb-07 22:00
Ram Murali1-Feb-07 22:00 
AnswerRe: Conversion Hex string to ASCII value Pin
Roger Stoltz1-Feb-07 22:18
Roger Stoltz1-Feb-07 22:18 
GeneralRe: Conversion Hex string to ASCII value Pin
Ram Murali1-Feb-07 22:39
Ram Murali1-Feb-07 22:39 

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.