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

What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function?

I have class member data which is a pointer to class member function.

However, I'm fail to compile the code.

What is the correct grammar to make a function call by using static
member data which is a pointer to a member function?
class Test
{
public :
typedef int (Test::*pfnOperate)(int x, int y);

static const pfnOperate m_arpOperate[2];

public :
int Add(int x, int y);
int Subtract(int x, int y);
void Foo();
};

const Test::pfnOperate Test::m_arpOperate[2] = {Test::Add,
Test::Subtract};

int Test::Add(int x, int y)
{
return x + y;
}

int Test::Subtract(int x, int y)
{
return x - y;
}

void Test::Foo()
{
int result;

result = (Test::m_arpOperate[1])(10, 5); // error C2064: term does
not evaluate to a function
}

int main(int argc, char* argv[])
{
Test t;

t.Foo();
return 0;
}

Jul 6 '07 #1
3 1844
za******@gmail.com wrote:
I have class member data which is a pointer to class member function.

However, I'm fail to compile the code.

What is the correct grammar to make a function call by using static
member data which is a pointer to a member function?
http://www.parashift.com/c++-faq-lit....html#faq-33.5

--
rbh
Jul 6 '07 #2
On Fri, 06 Jul 2007 05:00:27 -0700, zaeminkr wrote:
I have class member data which is a pointer to class member function.

However, I'm fail to compile the code.

What is the correct grammar to make a function call by using static
member data which is a pointer to a member function?
class Test
{
public :
typedef int (Test::*pfnOperate)(int x, int y);

static const pfnOperate m_arpOperate[2];

public :
int Add(int x, int y);
int Subtract(int x, int y);
void Foo();
};

const Test::pfnOperate Test::m_arpOperate[2] = {Test::Add, Test::Subtract};
g++ insists I write:

const Test::pfnOperate Test::m_arpOperate[2] = {&Test::Add, &Test::Subtract};

I'm not clear on whether the standard actually requires this.
int Test::Add(int x, int y)
{
return x + y;
}

int Test::Subtract(int x, int y)
{
return x - y;
}

void Test::Foo()
{
int result;

result = (Test::m_arpOperate[1])(10, 5); // error C2064: term does not evaluate to a function

result = (this->*m_arpOperate[1])(10, 5);
}

int main(int argc, char* argv[])
{
Test t;

t.Foo();
return 0;
}
--
Lionel B
Jul 6 '07 #3
On 7 6 , 9 17 , Robert Bauck Hamar <roberth+n...@ifi.uio.nowrote:
zaemi...@gmail.com wrote:
I have class member data which is a pointer to class member function.
However, I'm fail to compile the code.
What is the correct grammar to make a function call by using static
member data which is a pointer to a member function?

http://www.parashift.com/c++-faq-lit....html#faq-33.5

--
rbh
Thanks but I already found that and it does not work.

Jul 6 '07 #4

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

Similar topics

30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
5
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all",...
7
by: jon wayne | last post by:
Hi I'm a little confused here about the lifetime of a static pointer to member function, Say, I declare,define & initialize a static ptr to mem function in the header file of a class(the class...
5
by: RocTheEngy | last post by:
Greetings c.l.c... I am trying to understand some structure definitions in working code (e.g. compiles, runs & produces expected results) that I have. I think I've trimmed the code to what is...
7
by: Uwe Grawert | last post by:
Hello, a C-function expects me to give a pointer to a function as parameter. i want to give this function a pointer to a member function of a class but the compiler gives me an error: void...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
1
by: Bushido Hacks | last post by:
A private utility function using a function pointer sounds ideal to me. I want to simpify writing the same set of loops. While there are a few functions that can't use it, setting and modifying...
4
by: Immortal_Nephi | last post by:
I had a lot of research to see how function pointer works. Sometimes, programmers choose switch keyword and function in each case block can be called. Sometimes, they choose ordinary function...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.