小编Mad*_*dal的帖子

为什么允许指向内联函数的指针?

我有两个问题:

1)为什么在C++中允许指向内联函数的指针?我已经读过内联函数的代码只是被复制到函数调用语句中,内联函数中没有编译时内存分配.那么为什么内联函数存在一个指针,因为内联函数没有固定的内存地址?

2)考虑以下代码:

inline void func()    
{
    int n=0;
    cout<<(&n);
} 
Run Code Online (Sandbox Code Playgroud)

它是否应该打印不同值的n每次func()调用地址?[因为我认为每次复制内联函数代码时,必须重新分配局部变量(而在正常函数的情况下,重新初始化会发生)]

我是初学者,为了加强我的概念,我问了这个问题.如果我在任何地方都错了,请纠正我.

c++ inline function

52
推荐指数
4
解决办法
6769
查看次数

C++中的函数指针歧义

我有两个问题:

Q1)函数名称本身是指针吗?

如果它们是指针,那么它们中存储了什么值?

否则,如果它们不是指针,那么它们是什么以及它们中存储了什么值?

如果我们认为函数名是指针.然后 :

void display(){...}

int main ()
{ 
    void (*p)();

    **p=display; //Works (justified**, because we are assigning one pointer into another)

    **p=&display; //Works (Not justified** If function name is a pointer (let say type*) , then &display is of datatype : type**. Then how can we assign type** (i.e. &display) into type * (i.e. p)??)

    **p=*display; //Works (Not justified** If function name is a pointer ( type *) ,then, how can we assign type (i.e. …
Run Code Online (Sandbox Code Playgroud)

c++ pointers function-pointers function

5
推荐指数
1
解决办法
212
查看次数

标签 统计

c++ ×2

function ×2

function-pointers ×1

inline ×1

pointers ×1