You appear to have declared digits
to be a local variable within storeData
. If there is a class member within the Encrypt
class, the class member is being hidden by the local variable…
To elaborate, when the compiler sees a line such as:
digits[4] = temp2;
It’s going to go looking for the declaration of digits
– it will begin by looking in the local scope (in this case the function scope), and if it doesn’t find it the compiler will expand its search out to the class, to the local file, the global namespace, etc. The exact logic it uses is well outside the scope of this question, but the important thing is that in your case, the first thing it finds is the line:
array<int, Encrypt::arraySize> digits;
within Encrypt::storeData()
. So it stops. It never finds digits
within the Encrypt
class because it already found it in the function! So it modifies the version of digits
within the function, and when the function returns, it happily destroys the function-local digits
(along with all the alterations you’ve made) and goes on its merry way. Encrypt::digits
never gets modified at all.
The solution is to remove the line array<int, Encrypt::arraySize> digits;
from Encrypt::storeData()
, and also to remove const
from the function declaration, because if your function’s purpose is to modify the class’ data, it shouldn’t be const
in the first place.
4
solved Can’t get the display member function to print the modified values. Have included code snippets