我想创建一个类A的对象。编译工作正常,但链接器抱怨LNK2019无法解析的外部符号D :: D函数A :: A中引用。不能解决无法解决的外部错误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功能。我打开头文件以查看它们是否正在指向正确的文件,并确实如此。
你们有什么建议在哪里看下去以消除错误?你在某处发现错误吗?我搜查了太久以便自己解决。非常感谢帮助! 顺便说一句,我不得不改变类的实际命名,但我检查了伪名是否正确分配。如果需要其他文件来澄清错误,请让我知道,我会很高兴地把它们放在这里。
哦,废话,C的头文件应该在D.hpp中添加。这是在真实的代码中的情况,但我在这里意外地将其消除,因此添加C.hpp文件不是解决问题的方法 – Marijn 2012-03-09 19:27:11