Hello Shezshade,
The "&" means that you are passing the variable by reference which means that you are using the variable that was passed to the function in the function call.
In this case the function"multiArrayCipher" creates the variable "vector <char> multiArrayOne" which is passed to the function "arrayOutput". Without using the "&" only a copy of the vector is passed to the function. In the case of this program this time chanced are made to the copy and do not get back to the original. Bassing by reference allows any changes to be reflected in the original. Then there is the question of the overhead it costs to make a copy of something. Sometimes it makes no difference, but in a large program it could save a lot of time to pass by reference.
The class is looking better with the variables in the private section. Although it is not common practice to initialize variables in the definition. This is reserved for the ctor. I would also change the character array to a "std::string", it works the same way.
I would write the class this way:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class functions
{
private:
std::string alphabet;
string sentance;
int counter;
public:
functions // <--- Default ctor
{
alphabet = "ABC...Z";
counter = 0;
}
|
The other thing I would do is put the class in a header file and the functions in a ".cpp" file, but that is me.
The use of the function "collectAlphabet" is not needed. This can be done easier in the ctor when a class object is created.
Another way to write the for loop without the use of a file:
1 2
|
for (int j = 0, ch = 'A'; j < 26; j++, ch++)
alphabet[j] = ch;
|
This is more for future reference.
In the "arrayFill" function line 40 should be written as
tempArray.push_back(sentance[j])
and lines 41 and 42 would not be needed unless you would need the "counter" on line 42. In the first program I made this change and it worked fine.
Hope that helps,
Andy