Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误LNK2019:派生类中未解析的外部符号_C++ - Fatal编程技术网

C++ 错误LNK2019:派生类中未解析的外部符号

C++ 错误LNK2019:派生类中未解析的外部符号,c++,C++,在另一个项目中调用派生类的构造函数时出错。我在代码中省略了一些细节。我正在使用Visual Studio 2012 -基类/派生类和测试文件位于两个不同的项目中。基类/派生类可以毫无问题地编译 -当注释构造函数行时,可以成功编译测试项目 -Test.cpp与派生函数文件中的其他构造函数配合得很好 // Test.cpp #include "DerivationFunction.h" Child con(123, 123); // error LNK2019: unresolved exter

在另一个项目中调用派生类的构造函数时出错。我在代码中省略了一些细节。我正在使用Visual Studio 2012

-基类/派生类和测试文件位于两个不同的项目中。基类/派生类可以毫无问题地编译

-当注释构造函数行时,可以成功编译测试项目

-Test.cpp与派生函数文件中的其他构造函数配合得很好

// Test.cpp
#include "DerivationFunction.h"

Child con(123, 123);  // error LNK2019: unresolved external symbol "public: __thiscall Child::Child(unsigned short,unsigned int)" (??Child@@QAE@GI@Z) referenced in function _main 
基类和派生类的头文件:

// DerivationFunction.h
class Base
{
public:
    virtual void AppendEnums() = 0;
    static int CopyBuffer();
    uint16 GetFeatureID();

protected:
    uint16 baseValue;
    static int Copy();
};

// Child class
class Child : public Base
{
public:
    uint32 childValue;
    Child(uint16 featureID, uint32 value);
    void AppendEnums();
};
源文件:

// DerivationFunction.cpp
int Base::CopyBuffer()
{
    return 0;
}

uint16 Base::GetFeatureID()
{
    return baseValue;
}

int Base::Copy()
{
    return 0;
}

// Child class
Child::Child(uint16 featureID, uint32 value)
{
    baseValue = featureID;
    childValue = value;
}

void Child::AppendEnums()
{
}

最简单的答案是,您尚未在main中构建并包含实现文件,因此链接器无法找到
子构造函数的代码。请在MSDN帮助中查找该特定错误代码,并检查其中的所有可能性。

最简单的答案是,您尚未将实现文件构建并包含在main中,因此链接器无法找到
子构造函数的代码。在MSDN帮助中查找该特定错误代码,并检查其中的所有可能性。

如果要在另一个项目中使用这些类,则可以包含整个源(标题和cpp文件)并生成它们,或者从DLL项目中导出它们并将其导入其他项目中.

如果你想在另一个项目中使用这些类,那么你要么包含整个源文件(头文件和cpp文件)并构建它们,要么从DLL项目中导出它们并导入到其他项目中。

@hmjd抱歉,这是一个输入错误。我故意省略了一些细节,比如参数。参数应该没有问题。在子AppendEnums类定义中也使用virtual(即:virtual void AppendEnums())@user1654209,这是不必要的(请参阅)。请确保在源文件中包含的某个标头中没有重定义uint16和/或uint32。尝试在AppendEnum定义和实现中使用unsigned short和unsigned int来检查这种不相关的重新定义。链接错误发生在链接时(编译时之后)。Child.cpp可以引用正确的int16/32,而main.cpp在包含Child.h之前包含另一个头,并使链接器查找另一个实现。我最初的建议只是简单地检查这类问题,因为原语类型是不可能的redefined@hmjd对不起,这是个打字错误。我故意省略了一些细节,比如参数。参数应该没有问题。在子AppendEnums类定义中也使用virtual(即:virtual void AppendEnums())@user1654209,这是不必要的(请参阅)。请确保在源文件中包含的某个标头中没有重定义uint16和/或uint32。尝试在AppendEnum定义和实现中使用unsigned short和unsigned int来检查这种不相关的重新定义。链接错误发生在链接时(编译时之后)。Child.cpp可以引用正确的int16/32,而main.cpp在包含Child.h之前包含另一个头,并使链接器查找另一个实现。我最初的建议只是简单地检查这类问题,因为基本类型无法重新定义