如何访问不同类中方法中的变量,例如本代码中的变量。
#include <iostream>
using namespace std;
class Student
{
public:
void Addition()
{
int c=17;
}
};
int main()
{
}
如何在不返回值的情况下访问Student类中Addition方法中的变量c。
感谢阅读。
祝你度过美好的一天(:
您可以在类中使用setter和getter,然后使用它们在主中实现您想要的内容
private:
int c;
public:
void setIntC(int intC) { c = intC; }
int getIntC() const { return c; }