Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 包含Windows标头与用户定义的类名冲突_C++_Windows_Qt_Include - Fatal编程技术网

C++ 包含Windows标头与用户定义的类名冲突

C++ 包含Windows标头与用户定义的类名冲突,c++,windows,qt,include,C++,Windows,Qt,Include,Qt项目上的以下包含与我的用户定义类冲突: #ifdef Q_OS_WIN #include "qt_windows.h" #include "qwindowdefs_win.h" #include <shellapi.h> #endif 错误: \Desktop\Gui\MainScreen.cpp:953:错误:“Desktop::MessageBoxA”尚未声明 My Desktop::MessageBox与windows定义的MessageBoxA冲突。C++中的这个问题的

Qt项目上的以下包含与我的用户定义类冲突:

#ifdef Q_OS_WIN
#include "qt_windows.h"
#include "qwindowdefs_win.h"
#include <shellapi.h>
#endif
错误: \Desktop\Gui\MainScreen.cpp:953:错误:“Desktop::MessageBoxA”尚未声明

My Desktop::MessageBox与windows定义的MessageBoxA冲突。C++中的这个问题的标准解决方案是什么?
  • #未定义MessageBox
    (和其他冲突名称),或

  • 重命名您的类,或者

  • 将您对Windows API的使用封装到单独的.cpp文件中,这样您就不需要在任何地方都包含Windows标头,从而(在很大程度上)避免了这个问题

  • #未定义MessageBox
    (和其他冲突名称),或

  • 重命名您的类,或者

  • 将您对Windows API的使用封装到单独的.cpp文件中,这样您就不需要在任何地方都包含Windows标头,从而(在很大程度上)避免了这个问题


  • 您忘记了选项4:在每个源文件中首先包含Windows包含,因此名称mangling在您的项目中是一致的。@MarkRansom:我想到了,但是这个想法太可怕了,我不可能把它写下来。我相信它发生的频率比你想知道的要高。第三个选项是唯一安全的选项。你忘记了选项4:首先在每个源文件中包含Windows包含,所以,在你的项目中,“弄糟”这个名字是一致的。@Markransem:我想到了,但这个想法太可怕了,我不可能把它写下来。我相信这是偶然发生的,比你想知道的要多。第三个选项是唯一安全的选项。我必须说,这是Windows开发中最愚蠢的“功能”。头文件应该足够聪明,知道它们是用C++编译的,使用内联函数而不是宏。@ MalksSOM:了解微软,我相信他们已经尝试过了,并且有相当好的估计,这么做会破坏多少代码。例如,所有代码库都有一个
    #ifdef MessageBox
    ,我必须说这是Windows开发中最愚蠢的“功能”。头文件应该足够聪明,知道它们是用C++编译的,使用内联函数而不是宏。@ MalksSOM:了解微软,我相信他们已经尝试过了,并且有相当好的估计,这么做会破坏多少代码。例如,所有具有
    #ifdef MessageBox
     if (Desktop::MessageBox::question(this, tr("I am ready?"),
                                         tr("I am not ready yet!?")) == QDialog::Rejected )
                {
                    TRACE("Dialog rejected. I am not ready yet.");
                    return;
                }