 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Christopher Benson-Manica Guest
|
Posted: Fri Feb 27, 2004 4:11 pm Post subject: Problem with convoluted function pointer |
|
|
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
|
Posted: Fri Feb 27, 2004 4:23 pm Post subject: Re: Problem with convoluted function pointer |
|
|
"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
|
Posted: Fri Feb 27, 2004 4:23 pm Post subject: Re: Problem with convoluted function pointer |
|
|
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
|
Posted: Fri Feb 27, 2004 4:32 pm Post subject: Re: Problem with convoluted function pointer |
|
|
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
|
Posted: Fri Feb 27, 2004 4:40 pm Post subject: Re: Problem with convoluted function pointer |
|
|
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 |
|
 |
|
|
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
|
|