when i compile my program I get the following message:redefinition of 'keyWord' as different kind of symbol
string Vigenere::keyWord;
This is the class I'm using:
class Vigenere{
public:
Vigenere(int shamt); // Specify shift amount
string keyWord(string); // This is the keyword/secret word
string encrypt(string); // Encrypt message
string decrypt(string); // Decrypt message
string simplify(string); // Returns edited copy of string with only UPPERCASE letters
private:
char shift(char, int); // Shifts the order of the letters
int shamt; // Specify shift amount
};
and this where the program catches the error:
string Vigenere::keyWord;
Vigenere(string keyWord){
string key;
for (int i = 0; i < key.size(); i++){
if (key[i] >= 'A' && key[i] <= 'Z')
key += key[i];
else if (key[i] >= 'a' && key[i] <= 'z')
key += key[i] + 'A' - 'a';
}
}
If you want keyWord to actually be a string variable, put it in the private section. Instance variables are usually private and member methods (functions) are usually public.
1 2 3
private:
int shamt; // Specify shift amount
string keyWord;
You can have multiple constructors, but I usually just use one to initialize my instance variables. I use a setParameters(/*parameters*/) method to assign values to them.
Usually only the default constructor has the same name as the class. A destructor also does but you don't have to worry about that. Please send all of your code. Also use code braces which makes the code easier to read. Just click the "<>" in the format section and put your code between the blocks