大丈夫です、私はこのエラーでちょっと怪しいです。私がここでやろうとしているのは、UNICODEと_UNICODEが定義されているときにcharまたはwchar_tになるbasic_stringを作ることです(これはWINAPIにあります)。これはうまくいきますが、なんらかの理由で、宣言されているクラスの外でstd :: basic_stringを受け取る関数を定義できません。basic_string <TCHAR>は宣言された場所の外での定義を許可していません
TEST.H
#ifndef TEST_H
#define TEST_H
#include <Windows.h>
#include <string>
class Test
{
public:
void func(std::basic_string<TCHAR> stringInput);
};
#endif
TEST.CPP
#include "test.h"
void Test::func(std::basic_string<TCHAR> stringInput)
{
MessageBox(NULL, stringInput.c_str(), TEXT("It works!"), MB_OK);
}
これはテストを主張し、リンクエラーを生じ:: FUNCは、定義されていませんでした:ここでは例です。しかし、私はちょうどこのようなクラス内で定義した場合:それは正常に動作します
#ifndef TEST_H
#define TEST_H
#include <Windows.h>
#include <string>
class Test
{
public:
void func(std::basic_string<TCHAR> stringInput)
{
MessageBox(NULL, stringInput.c_str(), TEXT("It works!"), MB_OK);
}
}
#endif
TEST.H。しかし、私は、宣言の誤りや組織化を避けるために、宣言と定義を別々のファイルに保存するのが本当に好きです。しかし、ここではキッカーです。以前のようにtest.cppでfuncを定義していて、main.cppでUNICODEと_UNICODEを定義していないと、リンクエラーが発生しません。だから、実際には、TCHARがwchar_tになったときにリンクエラーが発生するのは唯一の時間です。だからここに私のメインだと本当の迅速なエラー...
main.cppに
#define UNICODE // this won't compile when these are defined
#define _UNICODE
#include <Windows.h>
#include <string>
#include "test.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
Test test;
test.func(TEXT("wakka wakka"));
return 0;
}
エラー:
error LNK2019: unresolved external symbol "public: void __thiscall Test::func(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" ([email protected]@@[email protected][email protected][email protected]@@[email protected][email protected]@@[email protected]@@Z) referenced in function [email protected]
誰もが何が起こっているの手掛かりを持っていると私は行くかもしれない方法これを修正?
実際にすべてのオブジェクトファイルをリンクしていますか? –