Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Differentiating 2 methods with the same name for a pointer Pin
Code-o-mat6-Jan-10 3:44
Code-o-mat6-Jan-10 3:44 
GeneralRe: Differentiating 2 methods with the same name for a pointer Pin
Richard MacCutchan6-Jan-10 3:36
mveRichard MacCutchan6-Jan-10 3:36 
GeneralRe: Differentiating 2 methods with the same name for a pointer Pin
Code-o-mat6-Jan-10 3:47
Code-o-mat6-Jan-10 3:47 
GeneralRe: Differentiating 2 methods with the same name for a pointer Pin
Richard MacCutchan6-Jan-10 3:55
mveRichard MacCutchan6-Jan-10 3:55 
AnswerRe: Differentiating 2 methods with the same name for a pointer Pin
SimonSays6-Jan-10 5:07
SimonSays6-Jan-10 5:07 
AnswerRe: Differentiating 2 methods with the same name for a pointer Pin
Moak6-Jan-10 15:30
Moak6-Jan-10 15:30 
GeneralRe: Differentiating 2 methods with the same name for a pointer Pin
Code-o-mat6-Jan-10 21:29
Code-o-mat6-Jan-10 21:29 
GeneralRe: Differentiating 2 methods with the same name for a pointer Pin
Moak7-Jan-10 0:32
Moak7-Jan-10 0:32 
Well, when I saw function pointers I thought that the design pattern you try to implement is something like a callback or interchangeable functionality. In object oriented languages, polymorphism (virtual functions or delegates) provides exactly that and under the hood they are more or less function pointers, with the advantage that the compiler takes care of most things automatically (type safety, calling context). It could be worth to have a look at these possibilities.

For using virtual functions define a interface (pure virtual base class) that you can override:

class IFunctionInterface
{
public: virtual int Func(int x) = 0;
public: virtual int Func(int x, int y) = 0;
};

class CFunction1 : public CWhatever, public IFunctionInterface
{
public:
	CFunction1 ();
	virtual ~CFunction1 ();

	int Func(int x) { return x; }		//implementation of interface
	int Func(int x, int y) { return x + y; }
};

class CFunction2 : public CWhatever, public IFunctionInterface
{
public:
	CFunction2 ();
	virtual ~CFunction1 ();

	int Func(int x) { return x + x; }	//different implementation of interface!
	int Func(int x, int y) { return x * y; }
};


For delegates have a look at Boost library (function/bind/signal) or Fast C++ Delegates[^] here at CodeProject.

Hope this helps. Smile | :)
/M


QuestionDataBase Pin
jannathali5-Jan-10 22:38
jannathali5-Jan-10 22:38 
AnswerRe: DataBase Pin
_AnsHUMAN_ 5-Jan-10 23:09
_AnsHUMAN_ 5-Jan-10 23:09 
AnswerRe: DataBase Pin
«_Superman_»6-Jan-10 0:26
professional«_Superman_»6-Jan-10 0:26 
QuestionCapturing check/uncheck in checkbox in listcontrol Pin
itkid5-Jan-10 22:16
itkid5-Jan-10 22:16 
AnswerRe: Capturing check/uncheck in checkbox in listcontrol Pin
Naveen5-Jan-10 22:46
Naveen5-Jan-10 22:46 
GeneralRe: Capturing check/uncheck in checkbox in listcontrol Pin
itkid5-Jan-10 22:49
itkid5-Jan-10 22:49 
GeneralRe: Capturing check/uncheck in checkbox in listcontrol Pin
Naveen5-Jan-10 23:15
Naveen5-Jan-10 23:15 
Questionhow to contact the file extension with file type? Pin
nenfa5-Jan-10 20:37
nenfa5-Jan-10 20:37 
AnswerRe: how to contact the file extension with file type? Pin
Naveen5-Jan-10 21:17
Naveen5-Jan-10 21:17 
AnswerRe: how to contact the file extension with file type? Pin
Richard MacCutchan5-Jan-10 21:21
mveRichard MacCutchan5-Jan-10 21:21 
Questionhow to retrieve the hicons on the desktop? Pin
nenfa5-Jan-10 20:21
nenfa5-Jan-10 20:21 
AnswerRe: how to retrieve the hicons on the desktop? Pin
Code-o-mat5-Jan-10 22:26
Code-o-mat5-Jan-10 22:26 
QuestionResolution for Dialog Pin
Anu_Bala5-Jan-10 19:24
Anu_Bala5-Jan-10 19:24 
AnswerRe: Resolution for Dialog Pin
KingsGambit5-Jan-10 20:13
KingsGambit5-Jan-10 20:13 
AnswerRe: Resolution for Dialog Pin
Moak5-Jan-10 23:36
Moak5-Jan-10 23:36 
AnswerRe: Resolution for Dialog Pin
beko6-Jan-10 1:44
beko6-Jan-10 1:44 
AnswerRe: Resolution for Dialog Pin
SimonSays6-Jan-10 5:08
SimonSays6-Jan-10 5:08 

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.