Sep 27, 2015 06:36 AM
(This post was last modified: Sep 27, 2015 06:38 AM by DeafConn.)
Hello everyone. So I'm working with a class that has a private member variable that is an integer array of size 4. Here is the code for it:
http://pastebin.com/i9u5DtUi - MoveRate.h
http://pastebin.com/q1xd61VQ - MoveRate.cpp
Now if one looks at the code they can execute the following snippets:
Now, looking at the MoveRate.cpp, I have placed debug code in the setter for the A array. Running this program should give the following output:
Instead, I get this:
Can anyone explain this behavior? Thanks.
http://pastebin.com/i9u5DtUi - MoveRate.h
http://pastebin.com/q1xd61VQ - MoveRate.cpp
Now if one looks at the code they can execute the following snippets:
PHP Code
<?php
//The declaration of the object in the private field of a header
private:
MoveRate m_moveRate;
//A getter to access the private object
MoveRate DirectionSim::getMoveRate(){
return m_moveRate;
}
//Finally, a snippet to actually modify the private integer array.
getMoveRate().setAMoveRate(2, 0);
cout << "COMP: "<< getMoveRate().getAMoveRate()[0] << endl;
Now, looking at the MoveRate.cpp, I have placed debug code in the setter for the A array. Running this program should give the following output:
Code
VAL: 2 ACT: 2
COMP: 2Instead, I get this:
Code
VAL: 2 ACT: 2
COMP: 473122Can anyone explain this behavior? Thanks.

