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

Baffling function pointer typedf problem

Hi,
The following code compiles and runs great using Visual C++ 6.0:

a.cpp
-----
void A::DoSomething() {
cout << "test";
}

// notice: A::DoSomething() is *not* a static member function
b.hpp
-----
typedef void (A::*AFUNCPTR) ();

class B {
void ForAll(AFUNCPTR funcptr);
}

b.cpp
-----
void B::ForAll(AFUNCPTR funcptr) {
A *pNode = GetList().First();
while (pNode) {
(pNode->*funcptr)();
pNode = pNode->Next();
}
}

void B::DoIt() {
ForAll(A::DoSomething);
}

But using gcc 3.0.4 and 3.2.3 it produces the following error message:

b.cpp: In member function `void B::DoIt()':
b.cpp:238: no matching function for call to `B::ForAll(<unknown type>)'
b.hpp:92: candidates are: void B::ForAll(void (A::*)())
gmake: *** [b.o] Error 1

Any idea why?

Thanks in advance,
Swengtoo
Jul 22 '05 #1
2 1450
"Swengtoo" <sw******@my-deja.com> wrote...
Hi,
The following code compiles and runs great using Visual C++ 6.0:

a.cpp
-----
void A::DoSomething() {
cout << "test";
}

// notice: A::DoSomething() is *not* a static member function
b.hpp
-----
typedef void (A::*AFUNCPTR) ();

class B {
void ForAll(AFUNCPTR funcptr);
}

b.cpp
-----
void B::ForAll(AFUNCPTR funcptr) {
A *pNode = GetList().First();
while (pNode) {
(pNode->*funcptr)();
pNode = pNode->Next();
}
}

void B::DoIt() {
ForAll(A::DoSomething);
Add an ampersand before 'A::'. It's a requirement of the language:

ForAll(&A::DoSomething);
}

But using gcc 3.0.4 and 3.2.3 it produces the following error message:

b.cpp: In member function `void B::DoIt()':
b.cpp:238: no matching function for call to `B::ForAll(<unknown type>)'
b.hpp:92: candidates are: void B::ForAll(void (A::*)())
gmake: *** [b.o] Error 1

Any idea why?


See above
Jul 22 '05 #2
On 6 Feb 2004 08:47:31 -0800, sw******@my-deja.com (Swengtoo) wrote:
void B::DoIt() {
ForAll(A::DoSomething);
ForAll(&A::DoSomething);
But using gcc 3.0.4 and 3.2.3 it produces the following error message:

b.cpp: In member function `void B::DoIt()':
b.cpp:238: no matching function for call to `B::ForAll(<unknown type>)'
b.hpp:92: candidates are: void B::ForAll(void (A::*)())
gmake: *** [b.o] Error 1

Any idea why?


In conforming code, you need the & when taking the address of a member
function, in contrast to an non-member function which automatically
decays to a pointer in most contexts.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3

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

Similar topics

5
by: TimS | last post by:
I am getting a baffling File not found error (0x800A0035). I am writing asp on a windows 2000 server. I build a path and filename from several fields in a jet database using SQL commands, like...
3
by: Jan-Henrik Grobe | last post by:
Hallo, I am coming to this newsgroup with a very strange Problem. I have two c++ files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in B.cpp I have stored the callback...
2
by: paul.driegen | last post by:
Hi all, Hopefully some gurus here can offer some insight into possible causes of this problem..or at least point me in the right direction as to how to solve it. Consider:
2
by: bfrasca | last post by:
I have a well-formed XML file that I am trying to load into a dataset using the ReadXML method. It keeps telling me that "there are multiple root elements". I can view the data using XML Designer...
7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
12
by: Mike | last post by:
I have posted this before, but no one responds, so here it goes again. I think my question is intimidating people and I have no idea why?!? This is not a new concept. You can do this with other...
3
by: Brian Victor | last post by:
I'm trying to get FFTW (fftw.org) to work in such a way that it can be called from a managed C++ module. The approach I've found to generate the fewest linker errors is a mixed managed/unmanaged...
2
by: Double Echo | last post by:
Hi, Forgive me if I ask a dumb question, I'm new to classes and object programming with PHP, and cannot figure out what the problem is with this class. Maybe I have overlooked something but...
1
by: Tim Redfern | last post by:
Hi I'm having an issue that is probably obvious to somebody here but its baffling me.. I'm using python (2.5.1) on an embedded linux sytem system (kernel 2.6.19 I think) with only 32MB memory...
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.