红联Linux门户
Linux帮助

如何查看成员函数的地址?

发布时间:2010-08-20 01:00:40来源:红联作者:vfdff
[code]
#include
class TestClass
{
public :
int test1(int a) { return a<<2; }
}testclass;

int main(int argc,char** argv)
{
printf("test generic member function!\n");
printf("value = %d\n", &testclass.test1 );

return 0;
}[/code]我想看看成员函数test1的地址,为什么不能使用printf显示出来呢?
文章评论

共有 4 条评论

  1. vfdff 于 2010-09-05 02:13:19发表:

    不过这样说明上面的还是不通用
    看来 printf("value = %p\n", (void *)(&TestClass::test1) );并不是标准C

  2. alick 于 2010-08-21 13:37:01发表:

    我用的g++也就是gcc for c++
    linux编程哪来的VC6?

  3. vfdff 于 2010-08-21 00:18:33发表:

    [i=s] 本帖最后由 vfdff 于 2010-8-21 00:20 编辑 [/i]

    2# alick

    您在哪里编译通过呢?我在VC6下试过是不可以的

    Deleting intermediate files and output files for project 'ewew - Win32 Release'.
    --------------------Configuration: ewew - Win32 Release--------------------
    Compiling...
    dd.cpp
    D:\Program_Files\Microsoft Visual Studio\MyProjects\test\dd.cpp(19) : error C2440: 'type cast' : cannot convert from 'int (__thiscall TestClass::*)(int)' to 'void *'
    There is no context in which this conversion is possible

  4. alick 于 2010-08-20 11:01:26发表:

    下面是我的试验:[code]#include

    class TestClass
    {
    public :
    int test1(int a) { return a<<2; }
    }testclass;

    int foo()
    {
    return 0;
    }

    int main(int argc,char** argv)
    {
    printf("test generic member function!\n");
    printf("value = %p\n", (void *)(&TestClass::test1) );
    printf("foo value = %p\n", foo);

    return 0;
    }[/code]结果[code]test generic member function!
    value = 0x400638
    foo value = 0x4005e4
    [/code]