473,387 Members | 3,801 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 2248
"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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.