I'm trying to create an object of class A. Compilation works fine, but the linker complains about a LNK2019 unresolved external symbol D::D referenced in function A::A.
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
Base class dec.cpp contains an empty constructor I also give you D.cpp
#include "../D.hpp"
using namespace <name>;
D::D(std::vector<B*>* b)
{
bs = b;
}
std::vector<B*>* D::getB()
{
return bs;
}
and 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
Class C only contains an empty constructor
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
Now it gives an error that it cannot find D::D referenced in function A::A, and some errors that it cannot find B::B in both A::A and D::D. I already tried adding a main function, eliminating the base class definition, double-checked the inclusion of header file... When selecting "jump to declaration" or "jump to definition" in Visual Studio 10, it can find the exact D::D function. I opened the header files to see if they were directing to the correct file and it does.
Do you guys have any suggestions where to look next to eliminate the error? Do you spot the mistake somewhere? I searched too long to figure it out on my own. Help is very much appreciated! Btw, I had to change the actual naming of the classes, but I checked whether the pseudo-names were correctly assigned. If other files are needed to clarify the mistake, please let me know and I will happily put them here.