473,387 Members | 1,486 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,387 software developers and data experts.

pointer to function

static short gfunc(short a, short b)
{return 0;}

class B{
B();
short(m_func)(short, short);
}

B::B()
{
m_func = gfunc;
}
error C2659: '=' : overloaded function as left operand

I'm not very familiar with pointer to functions. Can you help?

Thank you,
Gernot

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #1
4 2249
"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2k************@uni-berlin.de...
static short gfunc(short a, short b)
{return 0;}

// 1. Create a type for the function pointer...

typedef short(*pfn)(short, short);
class B{
B();
short(m_func)(short, short);
// 2. Have a member variable of that type

pfn m_func;
}

B::B()
{
m_func = gfunc;
}

Rest should be fine:

// invoke the function
B bObj;
bObj.m_func(1, 2);

Regards,
Senapathy

error C2659: '=' : overloaded function as left operand

I'm not very familiar with pointer to functions. Can you help?

Thank you,
Gernot

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com

Jul 22 '05 #2

"Senapathy" <se*********@siemens.com> wrote in message
news:cc**********@news.mch.sbs.de...
"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2k************@uni-berlin.de...
static short gfunc(short a, short b)
{return 0;}

// 1. Create a type for the function pointer...

typedef short(*pfn)(short, short);


Ok, the type creation is not really required.... I just used it the way I am
always used to creating fn ptrs.
class B{
B();
short(m_func)(short, short);


Just change this to short( * m_func)(short, short);
^^^^
After all you want to declare a function _pointer_ !

Regards,
Senapathy

// 2. Have a member variable of that type

pfn m_func;
}

B::B()
{
m_func = gfunc;
}


Rest should be fine:

// invoke the function
B bObj;
bObj.m_func(1, 2);

Regards,
Senapathy

error C2659: '=' : overloaded function as left operand

I'm not very familiar with pointer to functions. Can you help?

Thank you,
Gernot

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com


Jul 22 '05 #3
>
Just change this to short( * m_func)(short, short);
^^^^
After all you want to declare a function _pointer_ !


Ah, all right. What good would "void (a)()" be for? Would it mean the
same as "void a();" ?
Anyway, thank you.
Gernot
Jul 22 '05 #4
Gernot Frisch posted:

Just change this to short( * m_func)(short, short);
^^^^
After all you want to declare a function _pointer_ !


Ah, all right. What good would "void (a)()" be for? Would it mean the
same as "void a();" ?
Anyway, thank you.
Gernot

Yes, it would.

int (main)(void)
{

}
-JKOp
Jul 22 '05 #5

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

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
16
by: fix | last post by:
Hi all, I am new to C and I just started to program for a homework. I included my code down there. It is a fraction "class". I declared the Fraction struct, tried to create some invalid fraction,...
35
by: tuko | last post by:
Hello kind people. Can someone explain please the following code? /* Create Storage Space For The Texture */ AUX_RGBImageRec *TextureImage; /* Line 1*/ /* Set The Pointer To NULL...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
9
by: Morten Lemvigh | last post by:
Is it possible to pass a pointer to a constructor or a class definition as argument to a function? Maybe in a way similar to passing function pointers...? The function should construct a number...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
20
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...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
10
by: Richard Heathfield | last post by:
Stephen Sprunk said: <snip> Almost. A function name *is* a pointer-to-function. You can do two things with it - copy it (assign its value to an object of function pointer type, with a...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...

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.