[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显示出来呢?
vfdff 于 2010-09-05 02:13:19发表:
不过这样说明上面的还是不通用
看来 printf("value = %p\n", (void *)(&TestClass::test1) );并不是标准C
alick 于 2010-08-21 13:37:01发表:
我用的g++也就是gcc for c++
linux编程哪来的VC6?
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
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]