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 

Problem with convoluted function pointer

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





PostPosted: Fri Feb 27, 2004 4:11 pm    Post subject: Problem with convoluted function pointer Reply with quote



Given

typedef bool (TMyType::* FTYPE)(const void*,unsigned int, unsigned
int, unsigned int);

class TMyType{
public:
bool Send( const void *, unsigned int, unsigned int, unsigned int );
};

class TMyDerivedType : public TMyType
{
private:
A a;

public:
TMyDerivedType() : a(&TMyType::Send) {}
};


class A
{
private:
FTYPE f;

public:
void do_stuff() {f(NULL,1,2,3);}
A( FTYPE func ) {f=func;}
};

Why is f(NULL...) "call of nonfunction?" What have I done wrong?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Back to top
John Harrison
Guest





PostPosted: Fri Feb 27, 2004 4:23 pm    Post subject: Re: Problem with convoluted function pointer Reply with quote




"Christopher Benson-Manica" <ataru (AT) nospam (DOT) cyberspace.org> wrote

Quote:
Given

typedef bool (TMyType::* FTYPE)(const void*,unsigned int, unsigned
int, unsigned int);

class TMyType{
public:
bool Send( const void *, unsigned int, unsigned int, unsigned int );
};

class TMyDerivedType : public TMyType
{
private:
A a;

public:
TMyDerivedType() : a(&TMyType::Send) {}
};


class A
{
private:
FTYPE f;

public:
void do_stuff() {f(NULL,1,2,3);}
A( FTYPE func ) {f=func;}
};

Why is f(NULL...) "call of nonfunction?" What have I done wrong?

Not followed the correct syntax for pointers to member functions

From memory,

(this->*f)(NULL,1,2,3);

john



Back to top
Rob Williscroft
Guest





PostPosted: Fri Feb 27, 2004 4:23 pm    Post subject: Re: Problem with convoluted function pointer Reply with quote



Christopher Benson-Manica wrote in news:c1nq86$p95$1 (AT) chessie (DOT) cirr.com:

Quote:
Given

typedef bool (TMyType::* FTYPE)(const void*,unsigned int, unsigned
int, unsigned int);

class TMyType{
public:
bool Send( const void *, unsigned int, unsigned int, unsigned int );
};

class TMyDerivedType : public TMyType
{
private:
A a;

public:
TMyDerivedType() : a(&TMyType::Send) {}
};


class A
{
private:
FTYPE f;

public:
void do_stuff() {f(NULL,1,2,3);}
A( FTYPE func ) {f=func;}
};

Why is f(NULL...) "call of nonfunction?" What have I done wrong?


Member pointers only contain a reference to the member not the object,
to call via such a pointer you need an object:

FTYPE f = &TMyType::send;

TMyType obj, *ptr = &obj;

(obj.*f)( NULL, 1, 2, 3 );
(ptr->*f)( NULL, 1, 2, 3 );

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Back to top
Christopher Benson-Manica
Guest





PostPosted: Fri Feb 27, 2004 4:32 pm    Post subject: Re: Problem with convoluted function pointer Reply with quote

John Harrison <john_andronicus (AT) hotmail (DOT) com> spoke thus:

Quote:
typedef bool (TMyType::* FTYPE)(const void*,unsigned int, unsigned
int, unsigned int);

class TMyType{
public:
bool Send( const void *, unsigned int, unsigned int, unsigned int );
};

class TMyDerivedType : public TMyType
{
private:
A a;

public:
TMyDerivedType() : a(&TMyType::Send) {}
};

class A
{
private:
FTYPE f;

public:
void do_stuff() {f(NULL,1,2,3);}
A( FTYPE func ) {f=func;}
};

(left for context)

Quote:
(this->*f)(NULL,1,2,3);

Okay, thanks - that works. Unfortunately, now I'm informed that
TMyType is not a public base class of A... Now what? I should
probably note here that TMyDerivedType has it's own Send() function,
with a different signature.

(Thanks so much for continuing to bear with me!)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.













Back to top
Christopher Benson-Manica
Guest





PostPosted: Fri Feb 27, 2004 4:40 pm    Post subject: Re: Problem with convoluted function pointer Reply with quote

Christopher Benson-Manica <ataru (AT) nospam (DOT) cyberspace.org> spoke thus:

Quote:
(this->*f)(NULL,1,2,3);

Okay, thanks - that works. Unfortunately, now I'm informed that
TMyType is not a public base class of A... Now what? I should
probably note here that TMyDerivedType has it's own Send() function,
with a different signature.

Ah, I see what I wanted - not MyType::Send, but this->MyType::Send,
changing the typedef accordingly of course. At least it compiles
now...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.

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.