![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Get member function address
Is there an easy way to get the memory address to a member function? I don't really trust (understand) the output of this code...
#include <iostream>
class Foo
{
public:
void func()
{
std::cout << func << std::endl;
}
void func2()
{
std::cout << func2 << std::endl;
}
};
int main()
{
Foo foo;
foo.func();
foo.func2();
return 0;
}Output: 1 1 Why does it writes "1" to the screen in both functions? How do I make it print the real memory address? Thanks for your help! /Klarre
__________________
http://www.klarre.se |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
A member function doesn't have a unique address for each object, you need both a pointer to the member function an object to call it with. The the C++ FAQ.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
|
|
#3 | |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Quote:
/Klarre
__________________
http://www.klarre.se |
|
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3
![]() |
I believe you need to fully qualify the function name, i.e. &Foo::member_func. Here is a note from Microsoft on it-
Quote:
__________________
Visit my website BinaryNotions. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Combining languages | titaniumdecoy | Other Programming Languages | 12 | Jul 13th, 2006 2:03 PM |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 5:41 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 2:12 PM |
| Jackpot game | zorin | Visual Basic | 3 | Jun 10th, 2005 1:19 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |