Hi,
I am writing a simple chat program using Qt4. I decided to convert all text which is sent over the network into morse code as a side task to better understand string manipulation. I am having problems compiling now though. This is my first OO program and I decided to put the two arrays I use for conversion in the class header as private. I have other variables in the header file, but I had to make them const static to stop the compiler complaining. However the compiler still gives me errors with the arrays, they are below
Here is the relevant section from the header fileCode:In file included from kether.cpp:6: kether.h:40: error: a brace-enclosed initializer is not allowed here before ‘{’ token kether.h:66: error: invalid in-class initialization of static data member of non-integral type ‘const char [26][6]’ kether.h:67: error: a brace-enclosed initializer is not allowed here before ‘{’ token kether.h:68: error: invalid in-class initialization of static data member of non-integral type ‘const char [26]
Additionally, the compiler claims none of the variables used in the two morseCode functions have been declared even though some of them are used elsewhere in the program without problems (Ui::kether ui). This is pretty confusing as the functions are members of the class as seen above. The errors and the functions are belowCode:public slots: QString morseToText(QString morseCode); QString textToMorse(QString message); void on_ipConnect_clicked(); void on_ipDisconnect_clicked(); void on_ipAddress_textEdited(); void on_sendMessage_clicked(); void on_messageEntry_textEdited(QString message); void on_listen_clicked(); void readData(); void reportDisconnect(); void connectedToHost(); void handleNewConnection(); private: Ui::kether ui; QTcpSocket *tcpSocket; QTcpServer *tcpServer; const static quint16 port = 9001; qint64 oneByte; char endOfCharacter; const static char morse[26][6] = {{'.','-','\0'}, //a {'-','.','.','.','\0'}, //b {'-','.','-','.','\0'}, //c {'-','.','.','\0'}, //d {'.','\0'}, //e {'.','.','-','.','\0'}, //f {'-','-','.','\0'}, //g {'.','.','.','.','\0'}, //h {'.','.','\0'}, //i {'.','-','-','-','\0'}, //j {'-','.','-','\0'}, //k {'.','-','.','.','\0'}, //l {'-','-','\0'}, //m {'-','.','\0'}, //n {'-','-','-','\0'}, //o {'.','-','-','.','\0'}, //p {'-','-','.','-','\0'}, //q {'.','-','.','\0'}, //r {'.','.','.','\0'}, //s {'-','\0'}, //t {'.','.','-','\0'}, //u {'.','.','.','-','\0'}, //v {'.','-','-','\0'}, //w {'-','.','.','-','\0'}, //x {'-','.','-','-','\0'}, //y {'-','-','.','.','\0'} //z }; const static char lookup[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m' ,'n','o','p','q','r','s','t','u','v','w','x','y','z'};
Code:kether.cpp: In function ‘QString morseToText(QString)’: kether.cpp:147: error: ‘endOfCharacter’ was not declared in this scope kether.cpp:158: error: ‘ui’ was not declared in this scope kether.cpp:160: error: ‘morse’ was not declared in this scope kether.cpp:167: error: ‘lookup’ was not declared in this scope kether.cpp: In function ‘QString textToMorse(QString)’: kether.cpp:183: error: ‘lookup’ was not declared in this scope kether.cpp:186: error: ‘morse’ was not declared in this scope kether.cpp:191: error: ‘endOfCharacter’ was not declared in this scopeI'm sorry for the length of this post, I tried to cut out as much irrelevant code as possible. I figure this is probably a very simple problem, but after reading through some websites about OO I can't see anything obvious. Any ideas?Code:QString morseToText(QString morseCode) { QString message; int k,lastmarker,counter = 0; for(int j = 0;j < morseCode.size();j++) { while((k = morseCode.indexOf(endOfCharacter, k)) != -1) { QString character; for(int l = lastmarker;l < k; l++) { character = morseCode[l]; } for(int m = 0; m < character.size();m++) { if(counter > 25) { ui.chatWindow->append("Decoding of message failed, this should never happen."); } else if(character[m] != morse[counter][m]) { counter++; m = 0; } else if(morse[counter][m] == NULL) { message.append(lookup[counter]); } } k++; } } } QString textToMorse(QString message) { QString morseCode; for(int j = 0;j < message.size();j++) { for(int i = 0; i < 26; i++) { if(message[j] == lookup[i]) { int k = 0; while(morse[i][k] != NULL) { morseCode.append(morse[i][k]); k++; } morseCode.append(endOfCharacter); } } } }