我有以下基类和派生类结构。
基础/包含/Base.h
namespace A
{
namespace B
{
class Base
{
public:
Base();
Base(const Type type, const Name name);
virtual ~Base();
// Copy constructor
Base(const Base& other);
// Assignment operator
Base& operator= (const Base& rhs);
// Comparison
bool operator< (const Base& rhs);
std::string toString();
//These enums have been defined in same file above the class
enum Type mType;
enum Name mName;
};
}
}
基础/src/Base.cpp
#include "Base.h"
//and other required includes
namespace A
{
namespace B
{
Base::Base()
{
}
Base::Base(const Type type, const Name name)
{
}
Base::~Base()
{
}
// Copy constructor
Base::Base(const Base& other)
{
}
// Assignment operator
Base& Base::operator= (const Base& rhs)
{
}
// Comparison
bool Base::operator< (const Base& rhs)
{
}
std::string Base::toString()
{
}
}
}
基地/测试/test.h
#include "Base.h"
namespace A
{
namespace B
{
class Derived: public Base
{
public:
Derived();
Derived(const Type type, const Name name);
virtual ~Derived();
Derived(const Derived& other);
Derived& operator= (const Derived& rhs);
virtual std::string toString();
};
}
}
基地/测试/test.cpp
#include "test.h"
namespace A
{
namespace B
{
Derived::Derived()
{
}
Derived::Derived(const Type type, const Name name)
:Base(type, name)
{
}
Derived::~Derived()
{
}
Derived::Derived(const Derived& other)
{
}
Derived& Derived::operator= (const Derived& rhs)
{
}
std::string Derived::toString()
{
}
};
}
}
现在,我正在为基类目录构建 libBase.a。然后我试图在基本/测试目录中像这样在命令行上编译派生类:
g++ *.cpp -o Test \
-I /cygdrive/c/projects/base/include \
-L /cygdrive/c/projects/base/Build -lBase
但我收到如下错误:
/tmp/ccjLwXZp.o:Derived.cpp:(.text+0x10d): undefined reference to `A::B::Base::Base()
/tmp/ccjLwXZp.o:Derived.cpp:(.text+0x129): undefined reference to `A::B::Base::Base()
/tmp/ccjLwXZp.o:Derived.cpp:(.text+0x161): undefined reference to `A::B::base::Base(const Type type, const Name name)'
我为基类中定义的所有函数得到这些错误。我不确定,我做错了什么。我检查了 libBase.a 是否在适当的位置