Reputation:
How to access a variable in a method in a different class for example in this code.
#include <iostream>
using namespace std;
class Student
{
public:
void Addition()
{
int c=17;
}
};
int main()
{
}
How can i access variable c in Addition method in class Student without returning the value.
Thanks For Reading.
Have A Nice Day (:
Upvotes: 0
Views: 81
Reputation: 357
You can use a setter and getter in your class, then use them to achieve what you want in the main
private:
int c;
public:
void setIntC(int intC) { c = intC; }
int getIntC() const { return c; }
Upvotes: 3