473,513 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function Pointer...help!!

I have a class:
class MyCase
{
...
public:
...
short DoSomething( short sType, short sCase );
}

And oneother Class:
class TheWhole
{
public:
...
void SetDoFunction( short (*)( short sType, short sCase ) );
private:
short (*pDo)( short sType, short sCase );
}

In the main I create an instance of both object, so I would like set the
poiter's function pDo and use it inside at TheWhole class.

void TheWhole::SetFaiFunction( short (*pFun)( short sType, short sCase ) )
{
pFai = pFun;
}

So:

TheWhole *pAll = new TheWhole;
MyCase *pCase = new MyCase;

pAll->SetDoFunction( pCase->DoSomething );

My problems is that the compiler give error!
error C2664: cannot convert parameter 1 from 'short (short,short)' to 'short
(__cdecl *)(short,short)'

What is wrong? Someone can help me?

Thanks!

Jun 27 '08 #1
1 1049
On Mon, 12 May 2008 14:22:33 +0200, protopo wrote:
I have a class:
class MyCase
{
...
public:
...
short DoSomething( short sType, short sCase );
}

And oneother Class:
class TheWhole
{
public:
...
void SetDoFunction( short (*)( short sType, short sCase ) );
private:
short (*pDo)( short sType, short sCase );
}

In the main I create an instance of both object, so I would like set the
poiter's function pDo and use it inside at TheWhole class.

void TheWhole::SetFaiFunction( short (*pFun)( short sType, short sCase )
) {
pFai = pFun;
}

So:

TheWhole *pAll = new TheWhole;
MyCase *pCase = new MyCase;

pAll->SetDoFunction( pCase->DoSomething );

My problems is that the compiler give error! error C2664: cannot convert
parameter 1 from 'short (short,short)' to 'short (__cdecl
*)(short,short)'

What is wrong? Someone can help me?
http://www.parashift.com/c++-faq-lit...o-members.html

--
Lionel B
Jun 27 '08 #2

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

Similar topics

2
1651
by: QH Hong | last post by:
Compilation of the folowing program gives error message error C2664: 'solve' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' Here's the codes ==== class...
4
1979
by: Chris Bruyere | last post by:
Hi All, I just finished reading the FAQ page on fucntion points, for this ng, and I just wanted to clarify something. class MessageCenter { .... void addMessage(int i, Message* m);...
6
8808
by: keepyourstupidspam | last post by:
Hi, I want to pass a function pointer that is a class member. This is the fn I want to pass the function pointer into: int Scheduler::Add(const unsigned long timeout, void* pFunction, void*...
41
9986
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
5
17263
by: wongjoekmeu | last post by:
Hiya all, I am trying to use function pointers. I know that usually if you use a pointer to an object, you have to release the memory at the end by calling the delete keyword. I was wondering if...
2
4000
by: hs.samix | last post by:
Hello, I am trying to use a library which has a function, lets call it an external function, which wants a function pointer as one of its arguments. If I use that library in a C program, all...
7
8394
by: dries | last post by:
Hello lads, I'd like to do the following in C: 1. The user writes a function with predefined arguments and return value in a separate file. 2. The program is compiled as my written 'main'...
20
2199
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
7
3794
by: ghulands | last post by:
I am having trouble implementing some function pointer stuff in c++ An object can register itself for many events void addEventListener(CFObject *target, CFEventHandler callback, uint8_t...
0
7257
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
7379
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
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.