Change value of instance variables from another class?

I'm trying to change the values of some instance variables in my Controller Class so that when the user inserts values into main class it changes for Controller.

1
2
3
4
5
6
7
8
9
10
11
class Controller
{
public:
	Controller();
	~Controller();
	double PCFreq;
	__int64 CounterStart;
	int CounterCheck;
	ofstream out;
	int choice1;
	int choice2;


1
2
3
4
5
6
7
8
9
10
11
12
{
	PCFreq = 0.0;
	CounterStart = 0;
	out.open("finalStats.txt");
	CounterCheck = 0;

	pChampions.emplace_back(foo1);//0
	pChampions.emplace_back(foo2);//1
	pChampions.emplace_back(foo3);//2
	champ1 = pChampions.at(choice1);
	champ2 = pChampions.at(choice2);
}


The user should be able to choose which foo the want to use.

So I create an object of controller in main like this
Controller* con = new Controller()

Now my issues is, when I take user input (an integer) and try to do this
con->choice1 = choice1;

only the object of con's choice1 is = to user input.

However back at the class for Controller, choice1 hasn't received a value.

I can't initialize through Controllers constructor because I get the user input through a switch statement and the range of con would only be as far as the case.

What do I need to do in a situation like this?
Last edited on
Your main class either needs to own the Controller object or needs a reference to it. And then it needs to call a mutating function on the Controller object.
Well as stated earlier in main I have Controller* con = new Controller(), is that not what you mean by " own the Controller object".

Call a mutating function? Google has shown very little results on "Mutating Function C++". If you mean mutator function I had a setter function in Controller called setChoice1 and setChoice2 but it was achieving the same thing, it was only changing it for that instance of controller. Not for the controller class itself. Maybe I"m missing something?
Last edited on
Topic archived. No new replies allowed.