C++ cpp中的打印功能

C++ cpp中的打印功能,c++,function,C++,Function,为什么每次我在cpp中打印一个函数时,它都会打印1。i、 e #include <iostream> using namespace std; void f1(){ cout<<"called function f"; } int f2(){ cout<<"called f2"; return 1; } int main(){ cout << f2 <<endl; // p

为什么每次我在cpp中打印一个函数时,它都会打印1。i、 e

#include <iostream>
using namespace std;
void f1(){
   cout<<"called function f";
}
int f2(){
   cout<<"called f2";
   return 1;
}
int main(){
   cout << f2 <<endl; // prints 1
   cout << f1 <<endl; // still prints 1
}
#包括
使用名称空间std;
void f1(){

cout似乎正在判断函数(转换为指向函数的指针)不为null,返回
true
,并将
true
打印为1。这可以通过添加
cout
f来确认。未定义
。请发布a。您希望调用函数,而不是输出其函数指针:
cout编辑question@EkureEdem你的编辑甚至更能证明我的关心。你希望成为什么样的人nted?谢谢你的回答,但为什么要投反对票
#include <iostream>
using namespace std;
void f1(){
   cout<<"called function f";
}
int f2(){
   cout<<"called f2";
   return 1;
}
int main(){
   cout << std::boolalpha;
   cout << f2 <<endl; // prints true
   cout << f1 <<endl; // also prints true
}