Jump to content
  • Advertisement
Sign in to follow this  
Rip7

pointer to member function (with nested classes)

This topic is 4971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Indeed, the problem is solved now. Stupid from me, thanks for your excellent help ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!