Click here to Skip to main content
15,913,487 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: IOCP memory question Pin
Richard MacCutchan31-Aug-09 4:08
mveRichard MacCutchan31-Aug-09 4:08 
QuestionMake ActiveX have it's own thread Pin
manchukuo28-Aug-09 17:41
manchukuo28-Aug-09 17:41 
AnswerRe: Make ActiveX have it's own thread Pin
«_Superman_»30-Aug-09 21:24
professional«_Superman_»30-Aug-09 21:24 
Questionc++ Factory pattern for large number of different classes. (answered) Pin
Maximilien28-Aug-09 10:09
Maximilien28-Aug-09 10:09 
AnswerRe: c++ Factory pattern for large number of different classes. Pin
Garth J Lancaster28-Aug-09 14:26
professionalGarth J Lancaster28-Aug-09 14:26 
AnswerRe: c++ Factory pattern for large number of different classes. Pin
Stuart Dootson28-Aug-09 14:27
professionalStuart Dootson28-Aug-09 14:27 
GeneralRe: c++ Factory pattern for large number of different classes. Pin
Maximilien29-Aug-09 3:10
Maximilien29-Aug-09 3:10 
AnswerRe: c++ Factory pattern for large number of different classes. Pin
Cedric Moonen28-Aug-09 21:44
Cedric Moonen28-Aug-09 21:44 
I use an approach similar to the one from Stuart's but by using some little tricks, you can automate the process of registration.

So, the base principle is that the factory is aa wrapper around a map with the class identifier (type) as key and a function to create the object as value. So, this way your factory remains independant of your different objects.
Then, you have a public function on your factory to add a new creation function to the map:

// typedefinition of the creation function 
typedef BaseClass* CreateFunc ();

....
// In your factory:
void RegisterCreator(ObjectType type, CreateFunc* pFunc);


Now the "smart" trick is to let the classes register themselves through static initialization. At the top of the cpp file of your class, you add code similar to this:
int RegisterType1Class()
{
	CObjectFactory::GetInstance().RegisterCreator(Type1, Type1Class::CreateObject);
	return 0;
}
static int Temp = RegisterType1Class();


The Type1Class::CreateObjec is a static function of your class which simply creates a new instance of the class.

This mechanism allows you to automatically register objects to your factory through static initialization. Your factory has to be a singleton also.

Using this technique, your factory remains completely independant from all your different specific objects (it only has to know the base class), and you get rid of the big ugly switch.

Cédric Moonen
Software developer

Charting control [v2.0]
OpenGL game tutorial in C++

AnswerRe: c++ Factory pattern for large number of different classes. (answered) Pin
Iain Clarke, Warrior Programmer29-Aug-09 5:42
Iain Clarke, Warrior Programmer29-Aug-09 5:42 
Question2 questions of rich edit Pin
includeh1028-Aug-09 10:03
includeh1028-Aug-09 10:03 
AnswerRe: 2 questions of rich edit Pin
Code-o-mat29-Aug-09 1:41
Code-o-mat29-Aug-09 1:41 
QuestionC/C++ code of Vernam Cipher Algorithm Pin
Munna Bhagat28-Aug-09 6:44
Munna Bhagat28-Aug-09 6:44 
AnswerRe: C/C++ code of Vernam Cipher Algorithm Pin
CPallini28-Aug-09 7:02
mveCPallini28-Aug-09 7:02 
QuestionRe: C/C++ code of Vernam Cipher Algorithm Pin
Maximilien28-Aug-09 7:45
Maximilien28-Aug-09 7:45 
AnswerRe: C/C++ code of Vernam Cipher Algorithm Pin
Michael Schubert29-Aug-09 0:28
Michael Schubert29-Aug-09 0:28 
QuestionC/C++ code of Vernam Cipher Algorithm Pin
Munna Bhagat28-Aug-09 6:41
Munna Bhagat28-Aug-09 6:41 
QuestionC/C++ code of Vernam Cipher Algorithm Pin
Munna Bhagat28-Aug-09 6:41
Munna Bhagat28-Aug-09 6:41 
QuestionAnti virus live update corrupting file mapped shared memory Pin
avijaya28-Aug-09 4:59
avijaya28-Aug-09 4:59 
QuestionRe: Anti virus live update corrupting file mapped shared memory Pin
Randor 28-Aug-09 6:09
professional Randor 28-Aug-09 6:09 
AnswerRe: Anti virus live update corrupting file mapped shared memory Pin
avijaya28-Aug-09 6:15
avijaya28-Aug-09 6:15 
QuestionAfxDumpStack Pin
Krishnakumartg28-Aug-09 3:35
Krishnakumartg28-Aug-09 3:35 
AnswerRe: AfxDumpStack Pin
Randor 28-Aug-09 5:33
professional Randor 28-Aug-09 5:33 
GeneralRe: AfxDumpStack Pin
Krishnakumartg29-Aug-09 3:13
Krishnakumartg29-Aug-09 3:13 
QuestionWhile Splitting the String* it throws Error.... Pin
spalanivel28-Aug-09 1:19
spalanivel28-Aug-09 1:19 
QuestionRe: While Splitting the String* it throws Error.... Pin
CPallini28-Aug-09 1:41
mveCPallini28-Aug-09 1:41 

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.