コンパイルの問題があります。C++単純なコンパイルエラー
- 私は私が私の仕事をテストするために、1つのヘッダファイル
- そしてもちろんメインのを持っている1級
- を持っています。
コンパイルエラーが発生していますが、私が間違っていることを理解していません。
ヘッダーファイル:
#ifndef AGENT_H
#define AGENT_H
using namespace std;
class Agent
{
public:
Agent(string);
virtual ~Agent();
private:
string name;
};
#endif /* AGENT_H */
エージェントクラス(Agent.cpp)
#include "Agent.h"
using namespace std;
Agent::Agent(string _name)
{
this->name = _name;
}
Agent::~Agent()
{
delete this->name;
}
そして、私のメイン:
:#include <cstdlib>
#include <iostream>
#include "Agent.h"
using namespace std;
int main(int argc, char** argv)
{
Agent agent1("Danila");
return 0;
}
だから私は、このような奇妙なエラーを取得しています
undefined reference to `Agent::Agent(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/main.cpp:17: undefined reference to `Agent::~Agent()'
/main.cpp:17: undefined reference to `Agent::~Agent()'
あなたは私に何が間違っているのか理解してもらえますか?
なぜこのタグは "C"ですか? –
これはコンパイラエラーではありません。 **リンカエラー**です。最終的なリンカ呼び出しには、必要なオブジェクトファイルの1つが欠落している必要があります。 –
これはコンパイラエラーではなく、確かに "奇妙な"ものではなく、これはCとは関係ありません。 –