小编ali*_*i73的帖子

c ++函数指针没有改变

我已经定义了一些函数,我打印他们的地址是这样的:

#include<iostream>
#include <string>

using std::cout;

std::string func()
{
    return "hello world\n";

}

int func2(int n)
{
    if (n==0)
    {
        cout << func2 << std::endl;
        return 1;
    }

    cout << func2 << std::endl;

    return n + func2(n - 1);
}

//================================================
int main()
{
    int (*fun)(int) = func2;

    cout << fun;

    cout << std::endl << func2(3);
}
Run Code Online (Sandbox Code Playgroud)

当我打印函数的名称(地址)时,它们都1在我的编译器上打印(Mingw gcc 4.8).

它可以或它应该有所不同吗?

c++ pointers function

6
推荐指数
1
解决办法
101
查看次数

标签 统计

c++ ×1

function ×1

pointers ×1