2017-11-26 5 views
-2

このエラーにコード::モールス符号に 未定義の参照を取得する()コード:: alphacodeへ 未定義の参照() collect2は:エラー:ldが1の終了ステータスを返しましたC++コード::モールス符号に未定義の参照()とCode :: alphacodeに未定義の参照()

私はC++ morsecode.cppを使用してコンパイルしました。私は問題が何であるか把握できませんか?問題がどこにあるのかを見るために自分のコードを調べようとしましたが、問題の内容を把握することができません。 何か助けていただければ幸いです。おかげ

#include <string> 
#include <vector> 
#include <iostream> 

using namespace std; 

class Code 
{ 
public: 
Code();   //Default Constructor 

string decode(vector<string> message); //Decodes message 
private: 
vector<string> codewords; //codeword vector parallel to A-Z 

vector<char> alpha;  //this is the vector for A-Z  

vector<char> alphacode(); //Function that builds the vector alpha -A B C... 

vector<string> morsecode(); //function builds the vector codewords containing       morsecode 

char decode(string c);  //returns the character for the codeword c. 
}; 

Code::Code() 
{ 
codewords = morsecode(); 
alpha = alphacode(); 
} 

string Code::decode(vector<string> message) 
{ 
string temp; 
for(int i = 0; i < message.size(); i++) 
{ 
    temp += decode(message[i]); 
} 
return temp; 
} 

char Code::decode(string c) 
{ 
for(int i = 0; i < alpha.size(); i++) 
{ 
    if(c == codewords[i]) 
    { 
    return alpha[i]; 
    } 
} 
} 



// This function returns a vector containing the morse code 
vector<string> morsecode() 
{ 
vector<string> temp(28); 
temp[0] =".-"; 
temp[1] ="-..."; 
temp[2] ="-.-."; 
temp[3] ="-.."; 
temp[4] ="."; 
temp[5] ="..-."; 
temp[6] ="--."; 
temp[7] ="...."; 
temp[8] =".."; 
temp[9] =".---"; 
temp[10] ="-.-"; 
temp[11] =".-.."; 
temp[12] ="--"; 
temp[13] ="-."; 
temp[14] ="---"; 
temp[15] =".--."; 
temp[16] ="--.--"; 
temp[17] =".-."; 
temp[18] ="..."; 
temp[19] ="-"; 
temp[20] ="..-"; 
temp[21] ="...-"; 
temp[22] =".--"; 
temp[23] ="-..-"; 
temp[24] ="-.--"; 
temp[25] ="--.."; 
temp[26] ="......."; 
temp[27] ="x"; 
return temp; 
} 

// This returns a vector containing the alphabet a-z and " " 
vector<char> alphacode() 
{ 
vector<char> temp; 
for (char c='A'; c<='Z'; c++) 
    temp.push_back(c); 
    temp.push_back(' '); 
    temp.push_back('.'); 
return temp; 
} 

//Main Program 
int main() 
{ 
vector<string> message; 
string temp; 
Code c; 

cin >> temp; 

while (cin.good()) 
{ 
    message.push_back(temp); 
    cin >> temp; 
} 

cout << c.decode(message) << endl; 

return 0; 
} 
+4

[定義されていない参照/未解決の外部シンボルエラーとは何ですか?どうすれば修正できますか?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部記号エラーと方法i-fix) – user0042

答えて

0

定義スタンドアロン関数vector<string> morsecode()を所望vector<string> Code::morsecode()ありません。

+0

うわー、ありがとう!!私は彼らが提案した上記のリンクを参照しましたが、私はまだコンパイラが望んでいるものを理解できませんでした。それを指摘してくれてありがとう! – KMM