473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Jul 22 '05 #1
4 1201

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:c1**********@chessie.cirr.com...
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
Jul 22 '05 #2
Christopher Benson-Manica wrote in news:c1**********@chessie.cirr.com:
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/
Jul 22 '05 #3
John Harrison <jo*************@hotmail.com> spoke thus:
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)
(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.




Jul 22 '05 #4
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
(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.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: SeaPlusPlus | last post by:
I've got a problem... IE 6.0 twitches when I hover over a link then it won't twitch again for that group of links but will twitch the first time on the next group... and the next group... etc... ...
2
by: Mike | last post by:
I am trying to open a search results form based on the input from a prompt form. I am using the following code: --- Begin Code --- Private Sub btnSearch_Click() 'Dim Variable and assign data...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: Jordan | last post by:
I'm working with a Repeater using a custom function inside the <itemtemplate> to return a text string. The parameters SHOULD be (DateTime, DateTime, Int16) but the difficulties in getting DateTimes...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
7
by: Marcelo | last post by:
Hi everybody, I don't understand why I am having a problem in this code. The problem is that my pointer *phist in main method, it is declared. Then I send the pointer to my method, and this...
12
by: Joel Byrd | last post by:
I am making an AJAX call when any one of a number of inputs in a form (search criteria) are clicked, checked, changed, etc. When the user clicks, checks, whatever, I am trying to display a...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
5
by: KayC | last post by:
Hi I use SQLServer2000 and MS Access2000 I have the below SQL query which will not work as a Access PassThrough Query, I have tried replacing the @COB with a date string but the query hangs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.