本文介绍了C ++中的公共变量和私有变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我上课.有一个函数和一个变量.
I have a class. There is a function and a variable.
class myClass
{
private:
int num;
int Calc(int x);
};
int myClass::Calc(int x)
{
int num = 12536; //constant
return num /*First One (Global)*/ + num /*2nd One (1 inside the function*/ + x;
}
现在,如何在Calc函数中同时使用两个变量(数字)?我认为上述功能不正确.
Now, How Can I use both variables(num''s) inside Calc Function ? I think above function is not corrent.
推荐答案
this->num
推荐您的班级成员.
[edit]
实际上,最好的解决方案是更改名称,以消除任何歧义.
To referance your class member.
[edit]
Actualy the best solution would be to change the names so as to remove any ambiguity.
this->num
虽然也可以.
Will also work though.
这篇关于C ++中的公共变量和私有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!