【问题标题】:Macro Function _T() Causes Compiler Error [duplicate]宏函数_T()导致编译器错误[重复]
【发布时间】:2014-02-25 03:00:39
【问题描述】:

我正在尝试让我的 Win32 C++ 项目在 Dev C++ 中编译。该项目最初是在 Visual Studio C++ 2010 中制作的,因此它使用了许多 Unicode 宏函数,例如 _tcscmp_tcscat,最重要的是_T

我正在尝试让我的项目在 Dev C++ 中编译(为什么?这是一个很长的故事,但很有必要)。所以我试图定义宏函数_T,但是在使用这个宏函数时出现编译器错误:'La' undeclared (first use this function)

关于我的宏函数_T 哪里出错了有什么想法吗?

#if IS_DEVCPLUSPLUS > 0

    #undef _T
    #define _T(a) La
#endif


// Compile error occurs on below line: "'La' undeclared (first use this function)"
_tcscat( fileName, _T("\\*") ); 

// The end result should be
_tcscat( fileName, L"\\*" );

【问题讨论】:

  • @chris 谢谢L ##a 工作。你应该回答我才能接受
  • 重复答案没有多大意义。将人们指向另一个答案(通过重复)会更好。
  • _T 宏是为实现保留的。 VC++ 将它用于 Unicode/ASCII 切换,但 Dev-C++ 很可能将它用于其他目的。

标签: c++ unicode macros dev-c++


【解决方案1】:

您正在使用的#define,即使它适用于您的编译器,也是不完整的。

首先,使用标记粘贴预处理器符号。 其次,为 Unicode 和 MBCS 和构建定义 _T(x)。

#if defined (UNICODE) || defined (_UNICODE)
    typedef wchar_t TCHAR
    #define _T(a) L##a
#else
    typedef char TCHAR
    #define _T(a) a
#endif
#define TEXT(x) _T(x)

如果不是完整的 _T / TEXT 宏集,这应该可以让您接近。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多