Sign in to follow this  
Rip7

pointer to member function (with nested classes)

Recommended Posts

Hi, I have a list with possible commands that I can recieve from a client. When I find the right command I call the function that fits with it (a pointer to a member function). The problem is that the call to this function won't work. Some extracts from my code to clarify:

class Node:private
{
private:
        struct NetCommands
	{
		char *Command;
		void (Node::*pFunction) (char *pData);
	}CommandList [COMMAND];

void ParseData (char *pBuffer);
public:
Node:: Node(int Port, int MaxConnections);
};

Node:: Node(int Port, int MaxConnections)
{
CommandList[1].Command = "Verify";
CommandList[1].pFunction = &Node::VerifyClient;
	
CommandList[2].Command = "Disconnect";
CommandList[2].pFunction = &Node::DisconnectClient;
}

void Node::ParseData (char *pBuffer)
{
//parse code
((this->CommandList[Loop]).*pFunction)(pDividedData); //-> ERROR: pFunction undeclared (first use this function)
//parse code
}


If anyone else know's a better methode to execute command's from a client feel free to post it here :). [Edited by - Rip7 on February 8, 2005 11:53:20 AM]

Share this post


Link to post
Share on other sites
I believe you misused the function pointers. I think you should use something like:


void Node::ParseData (char *pBuffer)
{
//parse code
// YOURS: ((this->CommandList[Loop]).*pFunction)(pDividedData);
(this->*(CommandList[Loop].pFunction))(pDividedData);
//parse code
}


(PS: use either [ code ] or [ source ] tags, not <code>)

HTH,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this