用于继承和构造函数的未解析的外部符号c ++

时间:2016-06-17 09:09:22

标签: c++ inheritance

//Baseclass.h
class Baseclass {
private:
    uint8_t index;
public:
    Baseclass(uint8_t index);
}

//Baseclass.cpp
#include "Baseclass.h"
Baseclass::Baseclass(uint8_t index) {
    index = index;
};

//Subclass.h
#include "Baseclass.h"
class Subclass : public Baseclass {
public:
    Subclass();
};

//Subclass.cpp
#include "Subclass.h"
#include "Baseclass.h"
Subclass::Subclass() : Baseclass(0) {};

我错过了什么?我一直收到LNK2019错误

严重级代码描述项目文件行抑制状态 错误

LNK2019 unresolved external symbol "public: __thiscall Baseclass::Baseclass(unsigned char)" (??Baseclass@@QAE@E@Z) referenced in function "public: __thiscall Subclass::Subclass(void)" (??Subclass@@QAE@XZ)    

1 个答案:

答案 0 :(得分:1)

它无法链接Baseclass构造函数。你确定编译它没有问题吗?如果您复制粘贴的所有代码,则在基类结尾处缺少分号。