By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,436 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,436 IT Pros & Developers. It's quick & easy.

Returning a pointer to a nonstatic member function?

P: n/a
I have this code:

typedef BraidedNode* (BraidedNode::*NodeGet)() const;

NodeGet test()
return BraidedNode::getNextID;

This code compiles under MSVC 7.1, but g++ (GCC 3.4.4) will not compile
it. Maybe I'm missing a subtle portion of the standard.... I know
that the above is at least partially correct (MSVC compiles it). Does
anyone know what I need to do to get this to compile?

BraidedNode is a class
getNextID is a non-static member function of BraidedNode
BraidedNode::getNextID matches the NodeGet typedef

Anyone have an insights?

Nov 4 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
Sorry, forgot to mention, this is the error message:
Call.cpp: In function `BraidedNode*(BraidedNode::* test())() const':
Call.cpp:7: error: invalid use of non-static member function
`BraidedNode* BraidedNode::getNextID() const'
Call.cpp:7: error: invalid use of non-static member function

Nov 4 '05 #2

P: n/a
to get a pointer to a member function you have to prepend the function
with the address-of (&) operator. only global functions are implicitely
converted to pointers.


NodeGet test()
return &BraidedNode::getNextID;

Nov 4 '05 #3

P: n/a
That fixed it, thank you.

Nov 4 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.