【发布时间】:2011-10-21 12:21:37
【问题描述】:
c和c++中的函数指针有什么区别?当我在 c++ 中打印函数指针时,它给出了 1,但在 c 中它给出了一个地址。
#include <iostream>
int fun()
{}
typedef int (*f)();
int main()
{
f test = fun;
std::cout << reinterpret_cast<f>(test);
}
#include <stdio.h>
int fun()
{}
int (*f)();
int main()
{
f = fun;
printf("%p", f);
}
【问题讨论】:
-
你的 c++ 代码中的 f test = fun 是什么意思,我猜它甚至不会编译
-
@niko - 试试看,确实如此。
-
reinterpret_cast<f>(test);拥抱?