枚举不命名类型(无循环依赖关系)
Enum does not name type, (no cyclic dependecy)
我遇到了一个问题,编译器尖叫着枚举不命名类型。我在这里查看了其他帖子(枚举不命名类型),但其中大多数是因为循环依赖问题。
input/RegisterKeyEventCallback.h 中的代码
#pragma once
#include "UserDefinableInput.h"
#include "../Game/Other/CallBack/CallBack.h"
#include "../Containers/LinkedList/LinkedList.h"
#include "../HashFunctions/HashFunctions.h"
using namespace std;
class InputManager;
/**
* @brief structure for saving all callbacks that belong to one ID.
*/
struct RegisteredKeyEventCallback
{
enum KEY_EVENT_TYPE_ENUM
{
KEY_PRESS, /**< When key was released and is pressed. Fired only once */
WHILE_KEY_DOWN, /**< Fired while the key is down. Multiple times */
KEY_RELEASE, /**< When key was pressed and is released now. Fired only once */
_NULL
};
/**
* @brief Creates new empty instance
*/
RegisteredKeyEventCallback();
~RegisteredKeyEventCallback();
...
};
哈希函数.h
#pragma once
struct RegisteredKeyEventCallback;
struct KEY_EVENT_TYPE_ENUM_Hasher
{
size_t operator()(const RegisteredKeyEventCallback::KEY_EVENT_TYPE_ENUM& k) const;
};
对不起,如果我是瞎子,但我看不到它。循环依赖不应该存在,正如我正向声明的那样,我提供的hashfunctions.h是所有代码。
仍然,得到编译错误错误:结构中的KEY_EVENT_TYPE_ENUM RegisterKeyEventCallback 不命名类型。
任何帮助将不胜感激。谢谢。
编辑:感谢您的建议,多亏了您,我设法解决了它
input/RegisterKeyEventCallback.h 中的代码
#pragma once
#include "UserDefinableInput.h"
#include "../Game/Other/CallBack/CallBack.h"
#include "../Containers/LinkedList/LinkedList.h"
#include "../HashFunctions/HashFunctions.h"
using namespace std;
class InputManager;
struct HashFunctions; //<---------------------------
/**
* @brief structure for saving all callbacks that belong to one ID.
*/
哈希函数.h
#pragma once
#include "../Input/RegisteredKeyEventCallback.h"
struct KEY_EVENT_TYPE_ENUM_Hasher
{
size_t operator()(const RegisteredKeyEventCallback::KEY_EVENT_TYPE_ENUM& k) const;
};
你是对的,你没有循环依赖,但这不是这里的问题。问题是,在HashFunctions.h
中,编译器不知道RegisteredKeyEventCallback::KEY_EVENT_TYPE_ENUM
是什么。
通过对RegisteredKeyEventCallback
类进行前向声明,您只对类本身进行前向声明,而不是对其成员进行前向声明。您需要在 HashFunctions.h
头文件中RegisteredKeyEventCallback
类及其成员的完整定义,这意味着您将获得需要以其他方式解决的循环依赖项。
相关文章:
- C++GTKMM gui循环依赖关系
- 如何在头文件中声明类模板(由于循环依赖关系)
- 如何在具有循环依赖的类中dynamic_cast?
- C++模板方法中的循环依赖关系
- 修复循环依赖项 c++17 标头
- 涉及全局对象的循环依赖C++
- 循环依赖,在继承类的情况下使用覆盖方法
- Wt::D bo 中的循环依赖关系
- 在包含窗口标头时难以解决循环依赖关系问题
- 解决循环依赖关系 c++ 的想法
- C++循环依赖关系,未声明的标识符
- C++ 中的循环依赖关系问题
- 错误 C2512 视觉C++(并且不是循环依赖项)
- CMake 外部和内部静态库的循环依赖关系
- 正在从继承中解析循环依赖项
- "std::shared_ptr"循环依赖关系是如何导致问题的
- 纯引用而不是weak_ptr来打破循环依赖关系
- "invalid use of incomplete type" .解决循环依赖关系
- 如何避免模板方法的循环依赖
- 循环依赖结构,使用前向声明时结构的错误重定义