Click here to Skip to main content
15,919,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Forced scoping as a programming technique? Pin
Nemanja Trifunovic14-Jun-07 6:28
Nemanja Trifunovic14-Jun-07 6:28 
GeneralRe: Forced scoping as a programming technique? Pin
Cyrilix14-Jun-07 6:43
Cyrilix14-Jun-07 6:43 
GeneralRe: Forced scoping as a programming technique? Pin
jbarton14-Jun-07 8:53
jbarton14-Jun-07 8:53 
GeneralRe: Forced scoping as a programming technique? Pin
Cyrilix14-Jun-07 9:38
Cyrilix14-Jun-07 9:38 
GeneralRe: Forced scoping as a programming technique? Pin
jbarton14-Jun-07 9:57
jbarton14-Jun-07 9:57 
GeneralRe: Forced scoping as a programming technique? Pin
Cyrilix14-Jun-07 10:38
Cyrilix14-Jun-07 10:38 
GeneralRe: Forced scoping as a programming technique? Pin
jbarton15-Jun-07 3:20
jbarton15-Jun-07 3:20 
GeneralRe: Forced scoping as a programming technique? [modified] Pin
Cyrilix15-Jun-07 3:45
Cyrilix15-Jun-07 3:45 
I am surprised that you were able to deduce so much from just seeing this code snippet -- your assumptions are almost 100% on the spot. The m_localWorkMap actually holds work IDs and the call to Process from m_threadPool returns the work ID so I can insert it into m_localWorkMap. In my ThreadPool class (not shown), I have a work ID being mapped to a WorkUnit. In my local (caller) class, CoreWorkUnit maps work IDs to resources that I need to free (namely cbwDest, as you can see above, which is the basest class of CallbackWrapperGeneric and CallbackWrapperSpecific) and the function name. Say I pass in MyFunction as my "function name", when the CoreWorkUnit constructor executes, it will set an enum value for CoreWorkUnit (Function_MyFunction). This is used when I get my data later on (I have to know which work ID corresponds to which work function that I actually called). I can easily fill this in by just passing the enum value directly (but one of my goals is to make PROCESS simple and as parameterless as possible to use, so I'll take that into account.

The below seems to work...

template<class T>
inline void MainWindow::Process(void (MainWindow::*funcPtr)(T&), T args)
{
	CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(T&), T>* cbwSpecific =
		new CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(T&), T>(this, funcPtr, args);
	CallbackWrapperGeneric<T>* cbwGeneric = cbwSpecific;
	CallbackWrapperDestroy* cbwDest = cbwSpecific;
	CoreWorkUnit* cWorkUnit = new CoreWorkUnit(Function_DoWork, cbwDest);
	m_localWorkMap.insert(map<int, CoreWorkUnit*>::value_type(m_threadPool->Process(cbwGeneric), cWorkUnit));
}


...with the following prototype...

template <class T> void Process(void (MainWindow::*funcPtr)(T&), T args);


To be honest, I didn't think a class member template function was possible without the class being a template class, so now I have dispelled another myth. Smile | :)


-- modified at 10:10 Friday 15th June, 2007
AnswerRe: Forced scoping as a programming technique? Pin
Nemanja Trifunovic14-Jun-07 6:27
Nemanja Trifunovic14-Jun-07 6:27 
AnswerRe: Forced scoping as a programming technique? Pin
bob1697214-Jun-07 8:12
bob1697214-Jun-07 8:12 
Questionsetting executable icon Pin
R Thompson14-Jun-07 5:44
R Thompson14-Jun-07 5:44 
AnswerRe: setting executable icon Pin
R Thompson14-Jun-07 6:11
R Thompson14-Jun-07 6:11 
AnswerRe: setting executable icon Pin
Michael Dunn14-Jun-07 6:28
sitebuilderMichael Dunn14-Jun-07 6:28 
QuestionRe: setting executable icon Pin
Hamid_RT14-Jun-07 19:44
Hamid_RT14-Jun-07 19:44 
QuestionSave Screenshot Pin
CDRAIN14-Jun-07 4:54
CDRAIN14-Jun-07 4:54 
QuestionRe: Save Screenshot Pin
David Crow14-Jun-07 5:40
David Crow14-Jun-07 5:40 
AnswerRe: Save Screenshot Pin
Naveen14-Jun-07 14:30
Naveen14-Jun-07 14:30 
QuestionRe: Save Screenshot Pin
Hamid_RT14-Jun-07 19:41
Hamid_RT14-Jun-07 19:41 
AnswerRe: Save Screenshot [modified] Pin
CDRAIN15-Jun-07 0:46
CDRAIN15-Jun-07 0:46 
GeneralRe: Save Screenshot Pin
Hamid_RT15-Jun-07 2:56
Hamid_RT15-Jun-07 2:56 
GeneralRe: Save Screenshot Pin
CDRAIN15-Jun-07 3:28
CDRAIN15-Jun-07 3:28 
GeneralRe: Save Screenshot Pin
Hamid_RT15-Jun-07 5:29
Hamid_RT15-Jun-07 5:29 
GeneralRe: Save Screenshot Pin
Hamid_RT15-Jun-07 6:06
Hamid_RT15-Jun-07 6:06 
GeneralRe: Save Screenshot Pin
CDRAIN16-Jun-07 2:25
CDRAIN16-Jun-07 2:25 
GeneralRe: Save Screenshot Pin
Hamid_RT16-Jun-07 9:07
Hamid_RT16-Jun-07 9:07 

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.