May 6, 2014 at 9:18pm UTC
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.
2 3 4 5 6 7 8 9 10 11 class Controller
2 3 4 5 6 7 8 9 10 11 12
PCFreq = 0.0;
CounterStart = 0;
CounterCheck = 0;
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
May 6, 2014 at 9:19pm UTC
May 6, 2014 at 9:41pm UTC
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.
May 6, 2014 at 11:13pm UTC
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
May 6, 2014 at 11:15pm UTC