您的位置:首页 > 其它

wxString 使用问题

2015-11-13 00:00 239 查看
摘要: 头文件使用 顺序问题,出现的winundef.h之类的错误

由于需求,在wxwidgets中在原来的代码上添加 #include <wx/wxString.h> 头文件,一直也没头文件顺序问题,

之前的顺序:

#include "winsock2.h"
#pragma     comment(lib,"WS2_32.LIB")
#include <iostream>
#include<stdio.h>
#include <wx/string.h>

报出的错误:

D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:38:20: error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateDialogParamW(HINSTANCE, LPCWSTR, HWND, DLGPROC, LPARAM)'
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h: In function 'HFONT__* CreateFont(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR)':
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:69:48: error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '14' to 'HFONT__* CreateFontW(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCWSTR)'
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h: In function 'HWND__* CreateWindow(LPCTSTR, LPCTSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)':
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:94:20: error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateWindowExW(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h: In function 'HMENU__* LoadMenu(HINSTANCE, LPCTSTR)':
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:111:44: error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HMENU__* LoadMenuW(HINSTANCE, LPCWSTR)'
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h: In function 'HWND__* FindText(LPFINDREPLACE)':
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:126:43: error: cannot convert 'LPFINDREPLACE {aka FINDREPLACEA*}' to 'LPFINDREPLACEW {aka FINDREPLACEW*}' for argument '1' to 'HWND__* FindTextW(LPFINDREPLACEW)'
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h: In function 'HICON__* LoadIcon(HINSTANCE, LPCTSTR)':
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:311:51: error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HICON__* LoadIconW(HINSTANCE, LPCWSTR)'
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h: In function 'HBITMAP__* LoadBitmap(HINSTANCE, LPCTSTR)':
D:\wxWidgets-3.0.2\include/wx/msw/winundef.h:324:55: error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HBITMAP__* LoadBitmapW(HINSTANCE, LPCWSTR)'

之后修改的头文件:

#include <wx/string.h>
#include "winsock2.h"
#pragma     comment(lib,"WS2_32.LIB")
#include <iostream>
#include<stdio.h>

编译通过:

虽然没明白具体原因,但是程序总算能够运行了,

这是从知乎上看到的两种说法:

关于C/C++的头文件包含顺序,Google style里面推荐这样的顺序:
C 系统文件
C++系统文件
其他库头文件
本项目内头文件

但是也看到一些开源库的头文件组织顺序是相反的:
本项目内头文件
其他库头文件
C++系统文件
C 系统文件

对于两种说法的解释:

第一种的优点:符合了从一般到特殊的顺序,先打地基再盖房子的思路比较容易理解。
第二种的优点:符合了从特殊到一般的顺序,也算是一种顺序啦。而且这种顺序能够暴露出你的库的头文件是不是包含了所有必需的头文件,如果某个你的库文件没有包含它必需的系统文件的话,那么这个顺序就会导致编译错误。为什么要暴露这种问题呢?是因为希望“如果用户只使用你的库里提供的函数,那么他只需包含你的库头文件即可,你的头文件会自己去包含所需头文件”,可以方便用户,否则用户怎么会知道你的库依赖啥文件呢?

参考来源:http://my.oschina.net/pandeng/blog/120719

http://www.zhihu.com/question/26963963
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: