Returning a pointer to a nonstatic member function?

C

Clay_Culver

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?

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

Anyone have an insights?
 
C

Clay_Culver

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
 
P

Peter Steiner

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.

try:

NodeGet test()
{
return &BraidedNode::getNextID;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top