[英]Linker issue in Visual Studio C++
我正在嘗試在VS 2017中使用C ++(空項目模板),但是在添加1個簡單類時立即遇到了鏈接器問題,所以我想我缺少了一些重要的東西...
我的項目如下所示:
test.h
:
#include <iostream>
class test
{
public:
test();
~test();
std::string getInfo();
};
test.cpp
:
#include "test.h"
test::test() {}
test::~test() {}
std::string getInfo() {
return "test";
}
和main.cpp
:
#include <iostream>
#include <string>
#include "test.h"
int main(int argc, char **argv) {
test t;
std::cout << "output: " << t.getInfo() << std::endl;
return 0;
}
我收到的鏈接器錯誤是臭名昭著的LNK2019:
LNK2019 unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl test::getInfo(void)" (?getInfo@test@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function main
有什么想法我在這里做錯了嗎? 謝謝!
在文件test.cpp
您需要正確指定成員函數的范圍:
std::string test::getInfo() {
return "test";
}
注意test::
在getInfo()
之前
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.