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

问题描述

当我在类外制作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;
}

解决方法

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