在执行结束后,我们是否可以访问 INLINE 函数中的变量,就像我们在普通用户定义函数中没有的那样?

0 c++ inline function

当我在类外创建 input() 函数时,calculation() 函数不起作用......它与内联函数有关系吗??

#include <iostream>

using namespace std;

class price
{
public:
int pen;
int rubber;
int scale;

void input()
{
    cout<<"enter the variables\n";
    cin>>pen>>rubber>>scale;
    cout<<"\n"<<pen<<" "<<rubber<<" "<<scale;
}
};

void calculate(price p)
{
    int rate[2],total;
    rate[0]=p.pen*5;
    rate[1]=p.rubber*3;
    rate[2]=p.scale*4;
    total=rate[0]+rate[1]+rate[2];
    cout<<"\n"<<total;
}

int main()
{
    price a,b,c;
    a.input();
    calculate(a);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

joh*_*ohn 5

不,我们没有。inline对 C++ 函数的语义完全没有影响。它唯一的影响是链接器如何处理该函数。