最近想搞个UI框架学习玩玩,结果写着写着报下面的错误:
从网上查是头文件重复包含,但是我的所有的头文件都是使用避免头文件包含的结构写的,举例如下:
#pragma once
#ifndef UIDEFINE_H
#define UIDEFINE_H
#include "CDPI.h"
#include "UIControl.h"
#include "UIDialogBuilder.h"
#include "UIMessagePipe.h"
#include "WingAPP.h"
namespace WingUI
{
typedef std::wstring wingstr;
enum class StandardCursor
{
ARROW = 32512,
IBEAM = 32513,
WAIT = 32514,
CROSS = 32515,
UPARROW = 32516,
SIZENWSE = 32642,
SIZENESW = 32643,
SIZEWE = 32644,
SIZENS = 32645,
SIZEALL = 32646,
NO = 32648,
HAND = 32649,
APPSTARTING = 32650,
HELP = 32651,
PIN = 32671,
PERSON = 32672
};
}
#endif // !UIDEFINE_H
所有的代码已在GitHub
开源:https://github.com/Wing-summer/WingUI
只需在使用的参数类型前面添加 enum class 即可
在你的 WingApp.h
文件中,没有包含任何的头文件,但 StandardCursor: enum class
类型是自定义类型,且处于其他头文件中声明。编译器在编译 WingApp.h
头文件时,不清楚你的 StandardCursor
从何而来。
解决方案:
使用头文件前置数据类型声明,在 WingApp.h
头文件中预定义 StandardCursor
类型即可。如以下代码:
#ifndef WINGAPP_H
#define WINGAPP_H
namespace WingUI
{
/**
The data type is declared in advance.
which only tells the compiler that this data exists. Then the compiler will link to the entity's data type in the. cpp file during preprocessing.
*/
enum class StandardCursor;
// Other codes remain unchanged and can be passed after recompilation, which has been tested to be valid.
}
#endif // !WINGAPP_H