English 中文(简体)
基本内容 不允许在宣布的地点之外作出定义。
原标题:basic_string<TCHAR> doesn t allow definition outside the place it s declared
  • 时间:2012-04-07 23:32:27
  •  标签:
  • c++
  • winapi

oka,一米比照,与这一错误相fu。 在这里试图做的是,当联合国民主运动和——国际民联会(CNCODE)被定义时,便会作出基本的证明。 这确实奏效,但出于某种原因,无法界定一个得到 st function的职能:在宣布的类别之外铺设基础。 例如:

测试。

#ifndef TEST_H
#define TEST_H

#include <Windows.h>
#include <string>

class Test
{
public:
    void func(std::basic_string<TCHAR> stringInput);
};

#endif

测试。

#include "测试。"

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

it works fine. However, i really like to keep my declarations and definitions in separate files to avoid redefinition errors and for organization. Here s the kicker though. when i have func defined in 测试。 like before and don t define UNICODE and _UNICODE in my 主 席, i don t get the link errors. So really, the only time i get a link error is when TCHAR becomes a wchar_t. So here s my main and the error real quick...

主 席

#define UNICODE       // this won t compile when these are defined
#define _UNICODE

#include <Windows.h>
#include <string>

#include "测试。"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
    Test test;
    test.func(TEXT("wakka wakka"));
    return 0;
}

错误:

<代码>error LNK2019:未解决的外部编号“公开:无效__ 测试:func(级以下:基础:加强和设计;wchar_t,struct st :char_traits<wchar_t>,class :allotor<wchar_t> >) (?func@ Test@QAEXV?$basic_string@_WU$char_traits@_W@std@V?$alpositionor@_W@2@std@Z) 参考功能_WinMain@16

任何人都知道什么进展? 如何解决这一问题?

最佳回答

I think because you are putting #define UNICODE in main.cpp, the other part doesn t know about this. When test.cpp is compiled, UNICODE is not defined. You can try putting the UNICODE definition as project processor macro. Or in test.h, write #define UNICODE and #define _UNICODE before including Windows.h .

另一点是,由于你把Windows.h列入测试,你不应再把它列入主编。

考虑在视力演播室内设立一个默认项目,并使用<代码> Precompiled Headers 。 这样,就把这些问题列入 st。

#define UNICODE
#include <windows.h>
#include <string>
问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签