我遇到了标题所述的错误。我已确保以下内容:
- Include目录、include库和额外的include目录都设置正确
- 在属性中,子系统设置为CONSOLE
- Include目录、include库和额外的include目录都设置正确
- 在属性中,子系统设置为CONSOLE
我的代码注释如下:
LifeLib是一个包含我想要测试一些方法的类的项目。这些类在命名空间LifeLib中定义。其中之一是StornoTafel。testVariables没有在任何命名空间中定义。
我在StornoTafel的2个构造函数和1个方法的链接时出现了3次链接错误(在代码中有注明)。
//project Tester
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../LifeLib/StornoTafel.h"
#include "../LifeLib/testVariables.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Tester
{
TEST_CLASS(AggSelTest)
{
public:
LifeLib::StornoTafel stornoTafel_; // LNK2019
LifeLib::StornoTafel *stornoTafel_; // no error, but I need an instance and not a reference to proceed -> see init method
LifeLib::testVariables test_vars_; // everything is fine
TEST_METHOD_INITIALIZE(init) {
stornoTafel_ = StornoTafel(test_vars_.lapseProb); // when this line is commented out I only get the first error (see below)
}
}
}
// testVariables.h
#pragma once
#include <iostream>
#include <vector>
class testVariables {
public:
testVariables() {};
// here are a lot of vectors with values for testing purposes
std::vector<double> _lapseProb= {0,1,2}; // [...]
};
// StornoTafel.h
#pragma once
#include "masterheader.h"
namespace LifeLib {
class StornoTafel {
public:
StornoTafel(); //LNK2019
StornoTafel(std::vector<double> ProbabilityOfLapseInYearT); //LNK2019
StornoTafel(const StornoTafel &obj); //no error
StornoTafel operator=(StornoTafel const& rhs); //LNK2019
//! \name Getter
//@{
const std::vector<double>& Stornowahrscheinlichkeit() const;
//@}
protected:
std::vector<double> Stornowahrscheinlichkeit_;
};
inline const std::vector<double>& StornoTafel::Stornowahrscheinlichkeit() const {
return Stornowahrscheinlichkeit_;
}
}
//StornoTafel.cpp
#include "StornoTafel.h"
LifeLib::StornoTafel::StornoTafel() {
}
LifeLib::StornoTafel::StornoTafel(std::vector<double> ProbabilityOfLapseInYearT) {
Stornowahrscheinlichkeit_ = ProbabilityOfLapseInYearT;
}
LifeLib::StornoTafel::StornoTafel(const StornoTafel &obj) {
Stornowahrscheinlichkeit_ = obj.Stornowahrscheinlichkeit_;
}
LifeLib::StornoTafel LifeLib::StornoTafel::operator=(StornoTafel const& rhs) {
Stornowahrscheinlichkeit_ = rhs.Stornowahrscheinlichkeit_;
return *this;
}
//masterheader.h
#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <ctime>
详细错误信息:
- LNK2019 未解析的外部符号 "public: __cdecl LifeLib::StornoTafel::StornoTafel(void)" (??0StornoTafel@LifeLib@@QEAA@XZ),在函数 "public: __cdecl AggSelTester::AggSelTest::AggSelTest(void)" (??0AggSelTest@AggSelTester@@QEAA@XZ) 中引用
- LNK2019 未解析的外部符号 "public: __cdecl LifeLib::StornoTafel::StornoTafel(class std::vector >)" (??0StornoTafel@LifeLib@@QEAA@V?$vector@NV?$allocator@N@std@@@std@@@Z),在函数 "public: void __cdecl AggSelTester::AggSelTest::init(void)" (?init@AggSelTest@AggSelTester@@QEAAXXZ) 中引用
- LNK2019 未解析的外部符号 "public: class LifeLib::StornoTafel __cdecl LifeLib::StornoTafel::operator=(class LifeLib::StornoTafel const &)" (??4StornoTafel@LifeLib@@QEAA?AV01@AEBV01@@Z),在函数 "public: void __cdecl AggSelTester::AggSelTest::init(void)" (?init@AggSelTest@AggSelTester@@QEAAXXZ) 中引用
为什么会出现这些错误?