Compile Error

Hi All,

Following is some code from Quantum Programming book,  

class Fsm {
public:
typedef void // return value
(Fsm::* // class the function pointer is a member of
State) // pointer-to-member name
(unsigned const sig); // argument list
Fsm(State initial) : myState(initial) {} // ctor
virtual ~Fsm() {} // virtual xtor

protected:
State myState;
};

class CParser4 : public Fsm {
private:
void initial(unsigned const); //Line 33 // state-handler

public:
CParser4() : Fsm((State)initial) {} //Line 39 // ctor

};

I compile it under QNX 6.3.0 with error message as below:
C:/QNX630/workspace/CPARSER4/cparser4.h: In method CParser4::CParser4()': C:/QNX630/workspace/CPARSER4/cparser4.h:39: no matches converting function initial’ to type `void (Fsm::*)(unsigned int)’
C:/QNX630/workspace/CPARSER4/cparser4.h:33: candidates are: void CParser4::initial(unsigned int)

I would be very appreciated for your help.

thanks a lot.

shilunz

Is it because at the time CParser4’s constructor invokes Fsm’s constructor CParser4::initial() does not yet truly exist? If I modify your code ever slow slightly as follows, I no longer get any compile-time errors:

class Fsm
{
public:
	// return value class::pointer-to-member name(arg list)
	typedef void (*Fsm::State)(unsigned const sig);
	Fsm()
	{
	} // ctor
	virtual ~Fsm()
	{
	} // virtual xtor

	void SetStateHandler( State stateHandler)
	{
		myState = stateHandler;
	}
protected:
	State myState;
};

class CParser4 : public Fsm
{
private:
	static void initial(unsigned const)	//Line 33 // state-handler
	{
	}

public:
	CParser4() : Fsm()
	{
		SetStateHandler( initial);
	} //Line 39 // ctor
};