Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c和c+中函数指针之间的差异+;_C++_C - Fatal编程技术网

C++ c和c+中函数指针之间的差异+;

C++ c和c+中函数指针之间的差异+;,c++,c,C++,C,可能重复: < 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(

可能重复:

< 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);
}
#包括
int fun()
{}
typedef int(*f)();
int main()
{
f测试=乐趣;

std::cout主要区别在于您使用的打印机制。std::cout和printf具有不同的语义。std::cout将指针称为布尔数据,并打印0或1而不是地址。

真正的问题是,当您将指针流式传输到函数时,printf与“%p”和cout之间有什么区别


< >打印出指针在C++中的函数,尝试将其转换为char *并迭代字节(长度为sisioof(test))。函数指针不能转换为 Vult*/Cudio>,所以在使用C++ I/O的程序中,它转换为BoOL/COD>。C程序也是C++程序。编译C++时,应该没有区别。
你的意思是f测试=乐趣在你的C++代码,我猜它甚至不会compile@niko-试试看,确实如此。
reinterpret_cast(test);
Hug?+1聪明:我只是在想如何解决函数指针(方法)可能不适合标准指针的问题。