クラスAのオブジェクトを作成しようとしています。コンパイルはうまく動作しますが、関数A :: Aで参照されているLNK2019未解決の外部シンボルD :: Dについてリンカが文句を言います。未解決の外部エラーLNK2019エラーを解決できません
A.cpp
#include "../A.hpp"
using namespace <name>;
A::A(D* low, D* mid, D* high, M* m)
{
std::vector<B*>* lTC = split(low);
std::vector<B*>* mTC = split(mid);
std::vector<B*>* hTC = split(high);
D* lDC = new D(lTC);
D* mDC = new D(mTC);
D* hDC = new D(hTC);
mr = m;
procRDC = new std::vector<D*>();
procRDC->push_back(lDC);
procRDC->push_back(mDC);
procRDC->push_back(hDC);
}
std::vector<B*>* A::split(D* d)
{
std::vector<B*>* tc = new std::vector<B*>();
std::vector<B*>* ob = d->getB();
for (std::vector<B*>::iterator it = ob->begin(); it != ob->end(); ++it)
{
B* b= *it;
int a1 = b->getA;
int a2 = b->getA;
int a3 = b->getA;
B* b1 = new B(a1, a2, a3);
B* b2 = new B(a3, a2, a1);
tc ->push_back(b1);
tc ->push_back(b2);
}
return tc;
}
A.hpp
#ifndef A_HPP
#define A_HPP
#include "../dec.hpp"
#include "../D.hpp"
#include "../M.hpp"
#include "../B.hpp"
#include <vector>
using namespace <name>;
class A: public dec
{
protected:
M* mr;
std::vector<D*>* procRDC;
public:
A(D* low, D* mid, D* high, M* marketRound);
protected:
std::vector<B*>* split(D* d);
}; // class A
#endif
基本クラスdec.cppは私もD.cppにあなたの
#include "../D.hpp"
using namespace <name>;
D::D(std::vector<B*>* b)
{
bs = b;
}
std::vector<B*>* D::getB()
{
return bs;
}
とDを与える空のコンストラクタ が含まれています.hpp
#ifndef D_HPP
#define D_HPP
#include "../B.hpp"
#include <vector>
using namespace <name>;
class D: public C
{
protected:
std::vector<B*>* bs;
public:
D(std::vector<B*>* b);
std::vector<B*>* getB();
}; // class D
#endif
クラスCが唯一の空のコンストラクタが含まれてい
B.cpp
#inlcude "../B.hpp"
using namespace <name>
B::B(int a1, int a2, int a3)
{
a1 = a1;
a2 = a2;
a3 = a3;
}
int B::getA() { return a1; }
B.hpp
#ifndef B_HPP
#define B_HPP
#include "../O"
using namespace <name>
class B : public O
{
protected:
int a1;
int a2;
int a3;
public:
B(int a1, int a2, int a3);
public:
int B::getA();
};
#endif
今ではそれがD :: Dで参照を見つけることができないというエラーが発生します関数A :: Aと、A :: AとD :: Dの両方でB :: Bが見つからないエラーがあります。私はすでに、ヘッダーファイルのインクルードをダブルチェックして、基本クラス定義を削除するメイン関数を追加しようとしました... Visual Studio 10で "宣言にジャンプ"または "ジャンプ"を選択すると、D: :D関数。ヘッダーファイルを開いて、正しいファイルに移動しているかどうかを確認しました。
あなたは次のエラーを排除するためにどこを参考にするべきですか?間違いをどこかに見つけますか?私は自分自身でそれを理解するには時間がかかりすぎました。ヘルプは非常に高く評価されています! Btw、クラスの実際のネーミングを変更する必要がありましたが、疑似名が正しく割り当てられているかどうかを確認しました。間違いを明確にするために他のファイルが必要な場合は、私に知らせてください。
CのヘッダーファイルをD.hppに追加する必要があります。これは実際のコードでは当てはまりますが、私はここで事故で削除しました。したがって、C.hppファイルを追加することは問題の解決策ではありません – Marijn