C 对CODE :: morsecode()的不确定引用和对Code :: AlphaCode()的未定义引用
c++ Undefined Reference to Code::morsecode() and Undefined Reference to Code::alphacode()
获取此错误对代码:: morsecode()的未定义引用对代码的未定义引用:: alphaCode()Collect2:错误:LD返回1退出状态
我使用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;
}
定义的独立函数 vector<string> morsecode()
不是所需的 vector<string> Code::morsecode()
。
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code - C++ Debugger 無法啟動
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- Visual Studio Code "undefined reference to `WinMain@16'"
- C 对CODE :: morsecode()的不确定引用和对Code :: AlphaCode()的未定义引用
- 对使用 Code::Block 的类方法的未定义引用
- Crypto++ Code::blocks未定义引用问题
- 未定义的引用SDL与Code:: block