首页 新闻 会员 周边

c++语法错误标识符问题

0
悬赏园豆:30 [已解决问题] 解决于 2022-02-09 19:15

最近想搞个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

寂静的羽夏的主页 寂静的羽夏 | 小虾三级 | 园豆:1803
提问于:2022-01-15 18:06
< >
分享
最佳答案
0

只需在使用的参数类型前面添加 enum class 即可

寂静的羽夏 | 小虾三级 |园豆:1803 | 2022-02-09 19:15
其他回答(1)
0

在你的 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
怪小子 | 园豆:208 (菜鸟二级) | 2023-01-06 10:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册