Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Let a single document open Pin
_Flaviu22-Aug-11 22:44
_Flaviu22-Aug-11 22:44 
GeneralRe: Let a single document open Pin
Eugen Podsypalnikov23-Aug-11 0:41
Eugen Podsypalnikov23-Aug-11 0:41 
GeneralRe: Let a single document open Pin
_Flaviu23-Aug-11 1:51
_Flaviu23-Aug-11 1:51 
GeneralRe: Let a single document open Pin
Eugen Podsypalnikov23-Aug-11 5:39
Eugen Podsypalnikov23-Aug-11 5:39 
GeneralRe: Let a single document open Pin
_Flaviu22-Aug-11 22:46
_Flaviu22-Aug-11 22:46 
AnswerRe: Let a single document open Pin
Richard MacCutchan22-Aug-11 22:45
mveRichard MacCutchan22-Aug-11 22:45 
GeneralRe: Let a single document open Pin
_Flaviu22-Aug-11 22:49
_Flaviu22-Aug-11 22:49 
QuestionPointer to member function in struct Pin
Dean Seo22-Aug-11 18:29
Dean Seo22-Aug-11 18:29 
Hi,

Since I knew The Code Project, it has been helpful a lot.
Now I think I have a small misunderstanding about pointer to member function in a struct and I need your help, which will be priceless to me.

I am simply trying to see how pointer to member function works and it seems a little tricky.

The code I am having a problem with is below.


#include <iostream>
#include <conio.h>

#define KEY_ESC     27

using std::cout;
using std::endl;

class CAccount;

struct StateMap
{
	int input;
	void (CAccount::*mfp)();
};

class CAccount
{
public:
	enum
	{
		STATE_IDLE,
		STATE_INPUT,
		STATE_WAIT_ACK
	};

public:
	StateMap	map[3];
	int			m_iState;

	CAccount();

	void OnIdle();
	void OnInput();
	void OnWaitAck();
};//class CAccount


CAccount::CAccount(){
	map[0].input = 1;
	map[0].mfp = &CAccount::OnIdle;

	map[1].input = 2;
	map[1].mfp = &CAccount::OnInput;

	map[2].input = 3;
	map[2].mfp = &CAccount::OnWaitAck;

	m_iState = STATE_IDLE;
}

void CAccount::OnIdle()
{
	cout << "OnIdle()" << endl;
}

void CAccount::OnInput()
{
	cout << "OnInput()" << endl;
}

void CAccount::OnWaitAck()
{
	cout << "OnWaitAck()" << endl;
}


int main()
{
	int         ch = 0;
	int         i;
	CAccount    account;

	while ( ch != KEY_ESC )
	{
		ch = _getch();
		i  = 0;
		while ( account.map[i].input != 0 )
		{
			if ( ch == account.map[i].input )
			{
				(account.(map[i].*mfp))(); // compile error
			}//if
			i++;
		}//while
	}//while

	return 0;
}//main()


I just don't know the right syntax for that part.
How should I change that error line to make it work?

Thanks in advance.
AnswerRe: Pointer to member function in struct Pin
Eugen Podsypalnikov22-Aug-11 20:59
Eugen Podsypalnikov22-Aug-11 20:59 
GeneralRe: Pointer to member function in struct Pin
Dean Seo22-Aug-11 21:16
Dean Seo22-Aug-11 21:16 
GeneralRe: Pointer to member function in struct Pin
Richard MacCutchan22-Aug-11 22:43
mveRichard MacCutchan22-Aug-11 22:43 
GeneralRe: Pointer to member function in struct Pin
Chang Su Lee24-Aug-11 5:29
Chang Su Lee24-Aug-11 5:29 
GeneralRe: Pointer to member function in struct Pin
Richard MacCutchan24-Aug-11 6:09
mveRichard MacCutchan24-Aug-11 6:09 
GeneralRe: Pointer to member function in struct Pin
Dean Seo22-Aug-11 21:27
Dean Seo22-Aug-11 21:27 
QuestionIDE from programm in C++ Pin
Chargoy22-Aug-11 16:04
Chargoy22-Aug-11 16:04 
AnswerRe: IDE from programm in C++ Pin
Richard Andrew x6422-Aug-11 16:13
professionalRichard Andrew x6422-Aug-11 16:13 
AnswerRe: IDE from programm in C++ PinPopular
Albert Holguin22-Aug-11 16:40
professionalAlbert Holguin22-Aug-11 16:40 
GeneralRe: IDE from programm in C++ Pin
Chargoy27-Aug-11 5:43
Chargoy27-Aug-11 5:43 
QuestionHandle bluetooth pairing code Pin
Vijay Rajanna22-Aug-11 7:15
Vijay Rajanna22-Aug-11 7:15 
AnswerRe: Handle bluetooth pairing code Pin
«_Superman_»22-Aug-11 8:47
professional«_Superman_»22-Aug-11 8:47 
QuestionVC6 C++ can I prevent an "Internet Explorer Script Error" debug dialog popup [modified] Pin
cgb14322-Aug-11 6:43
cgb14322-Aug-11 6:43 
AnswerRe: VC6 C++ can I prevent an "Internet Explorer Script Error" debug dialog popup Pin
Code-o-mat22-Aug-11 7:46
Code-o-mat22-Aug-11 7:46 
GeneralRe: VC6 C++ can I prevent an "Internet Explorer Script Error" debug dialog popup Pin
cgb14322-Aug-11 9:12
cgb14322-Aug-11 9:12 
GeneralRe: VC6 C++ can I prevent an "Internet Explorer Script Error" debug dialog popup Pin
Code-o-mat22-Aug-11 9:40
Code-o-mat22-Aug-11 9:40 
GeneralRe: VC6 C++ can I prevent an "Internet Explorer Script Error" debug dialog popup Pin
xrg_soft@163.com23-Aug-11 5:37
xrg_soft@163.com23-Aug-11 5:37 

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.