A little help with Classes

Basically what I'm trying to do is INCREASE the value of a certain variable in the
Private: section in a Class, for example.

Class X {

public:

int setVar(int x) {
variableIwantToChange = x
}

void getVar() {
return variableIwantToChange;
}

private:

int variableIwantToChange;

}

I can now cout<<X.getVar();

But I can't change the value later on X.getVar(0++)

Thanks in advance.
But I can't change the value later on X.getVar(0++)


Use that setVar function you wrote to change the variable.
Sorry, but can you be more specific? Do you mean X.setVar(x++)?
The setVar function sets the value of the variable inside the class. Like this:

1
2
3
4
X someObject; // create an object of type X
someObject.setVar(4); // Set the variable variableIwantToChange to 4
someObject.setVar(8); // Set the variable variableIwantToChange to 8
someObject.setVar(-12); // Set the variable variableIwantToChange to -12 


So, you have a way to read the variable (getVar) and a way to set the variable. Can you come up with some way that you could read it, and then set it to whatever value you just read plus one?
Last edited on
Ohh, I see. Thanks!
Topic archived. No new replies allowed.