Hi there,

I'm so frustrated now =(

I have read the forums and this http://www.goingware.com/tips/member-pointers.html

But i still cannot get this to work:

class FileParser
	void load(char* file)
		MyDocumentClass _mDoc;


		// is this correct syntax?
		parse(_mDoc, &(FileParser::saveElement));

		// or is this correct?
		parse(_mDoc, &(this->saveElement));
	typedef void (FileParser::*ParseAction)(MyDocumentClass* doc);

	void parse(MyDocumentClass* doc, ParseAction action)
			// is this syntax correct?
	void save(MyDocumentClass* doc){}
	void print(MyDocumentClass* doc){}
	// etc...

I believe it is different than that described in the web article.....?

Hope someone can point out my mistake in the code.

[ after some time ]

// Ok I found out it is 
parse(_mDoc, (&FileParser::saveElement));
// instead of
parse(_mDoc, &(FileParser::saveElement));

But what is the difference here? address operator on the class name vs address operator on the class function?

>But what is the difference here? (&FileParser::saveElement) is parsed as the address of a class member. The parentheses are redundant in this case. &(FileParser::saveElement) is parsed as trying to access a static member and then take the address of it. saveElement isn't a static member, and if it were a static member, you wouldn't be able to use it as the address for a pointer to a member. End result: the compiler pukes on your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.