C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: pointer to member function

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Rolf Magnus
Guest





PostPosted: Fri Jul 04, 2003 5:04 pm    Post subject: Re: pointer to member function Reply with quote



Tux wrote:

Quote:

Hello,

let's say I have:

void test_func( double (*func)(in,int) )
{
// code ...
}


Could a pointer to a member function of an arbitrary class
to be converted to a pointer to an ordinary non-member function ?

No, not if that function is non-static. How would the compiler know
which object to call the member function for?

Quote:
I would like to write:

test_func(&SomeClass::func);



Back to top
John Harrison
Guest





PostPosted: Fri Jul 04, 2003 5:11 pm    Post subject: Re: pointer to member function Reply with quote




"Tux" <catina (AT) uni-bremen (DOT) de> wrote

Quote:

Hello,

let's say I have:

void test_func( double (*func)(in,int) )
{
// code ...
}


Could a pointer to a member function of an arbitrary class
to be converted to a pointer to an ordinary non-member function ?
I would like to write:

test_func(&SomeClass::func);

Thanks.

No it cannot, unless the member function is static. See the FAQ

http://www.parashift.com/c++-faq-lite/pointers-to-members.html

john



Back to top
Allen
Guest





PostPosted: Sat Aug 02, 2003 2:48 am    Post subject: Re: pointer to member function Reply with quote



Hi ES Kim,

You know, now that you've shown it to me, I think that I've seen how to
do that before. <slaps forehead>

Thanks for the help.
--

Best wishes,
Allen

No SPAM in my email !!


"ES Kim" <eskim (AT) svd (DOT) co.kr> wrote

Quote:
"Allen" <allen-terri-ng (AT) att (DOT) SPAM.net> wrote in message
news:lTEWa.84070$0v4.5609149 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net...
Sorry for the mispost. Apparently, if your subject line matches an
already
existing one, it includes it to that thread.

After reading the thread this ended up in, I'm wondering if this
would
work:

class A
{
public:
int func();
}

typedef int (*func)(void) myFuncPntr;

It's a wrong typedef syntax.

typedef int (A::*myFuncPntr)();
myFuncPntr pf = &A::func;
A obj;
int i = (obj.*pf)(); // the same as obj.func()

--
ES Kim





Back to top
Allen
Guest





PostPosted: Mon Aug 04, 2003 6:04 pm    Post subject: Re: pointer to member function Reply with quote

Hi Kim, all,

<comments inline>
"ES Kim" <eskim (AT) svd (DOT) co.kr> wrote

Quote:
"Allen" <allen-terri-ng (AT) att (DOT) SPAM.net> wrote in message
news:lTEWa.84070$0v4.5609149 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net...
Sorry for the mispost. Apparently, if your subject line matches an
already
existing one, it includes it to that thread.

After reading the thread this ended up in, I'm wondering if this
would
work:

class A
{
public:
int func();
}

typedef int (*func)(void) myFuncPntr;

It's a wrong typedef syntax.

typedef int (A::*myFuncPntr)();
myFuncPntr pf = &A::func;
A obj;
int i = (obj.*pf)(); // the same as obj.func()

I can't believe I missed this before.

What that does is create a pointer to the member function, but it still
requires the use of the object. What I'm looking for is a way to declare a
pointer to the _whole_thing_! Is that possible?
--

Best wishes,
Allen

No SPAM in my email !!





Back to top
Allen
Guest





PostPosted: Mon Aug 04, 2003 6:23 pm    Post subject: Re: pointer to member function Reply with quote

nevermind, I found an answer.
Thnx

"Allen" <allen-terri-ng (AT) att (DOT) SPAM.net> wrote

Quote:
Hi Kim, all,

comments inline
"ES Kim" <eskim (AT) svd (DOT) co.kr> wrote in message
news:bgf5id$44d$1 (AT) news1 (DOT) kornet.net...
"Allen" <allen-terri-ng (AT) att (DOT) SPAM.net> wrote in message
news:lTEWa.84070$0v4.5609149 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net...
Sorry for the mispost. Apparently, if your subject line matches an
already
existing one, it includes it to that thread.

After reading the thread this ended up in, I'm wondering if this
would
work:

class A
{
public:
int func();
}

typedef int (*func)(void) myFuncPntr;

It's a wrong typedef syntax.

typedef int (A::*myFuncPntr)();
myFuncPntr pf = &A::func;
A obj;
int i = (obj.*pf)(); // the same as obj.func()

I can't believe I missed this before.

What that does is create a pointer to the member function, but it
still
requires the use of the object. What I'm looking for is a way to declare
a
pointer to the _whole_thing_! Is that possible?
--

Best wishes,
Allen

No SPAM in my email !!







Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.