在命名空间内实例化时的 C++ "Does not name type"
c++ "Does not name type" when instantiating inside of namespace
我正在尝试使用命名空间来分割我的代码片段并重用一些名称。 当我创建一个新的命名空间时,编译器似乎失去了在该命名空间之外定义的类的范围。
我在UI_SHARED.h
中收到以下错误
错误"EZUI_Control_Label"未命名类型
此代码在没有命名空间定义的情况下工作正常。命名空间中的对象是否以某种方式失去了对包含的文件/类定义的访问权限?
UI_SHARED.h
#ifndef __UI_SHARED_H__
#define __UI_SHARED_H__
#include "EZUI_Control_Label.h"
namespace UI_SHARED{
EZUI_Control_Label Shared_Lbl_HLT("HLT:");
EZUI_Control_Label Shared_Lbl_MLT("MLT:");
EZUI_Control_Label Shared_Lbl_BK("BK:");
}
#endif
EZUI_Control_Lable.h
#ifndef __EZUI_CONTROL_LABEL_H__
#define __EZUI_CONTROL_LABEL_H__
//Includes
#include "EZUI_Control.h"
#include "../EZUI.h"
//Forward Declarations
class EZUI;
class EZUI_Control_Label : public EZUI_Control
{
//variables
public:
using EZUI_Control::Type;
enum EZUI_Control_Label_Type {None, LblString, LblFloat, LblDouble, LblInt, LblUInt, LblLong, LblULong, LblBool, LblBoolWithText, LblDigitalIO};
EZUI_Control_Label_Type Label_Type = None; //Not initialized to any value
protected:
private:
//When was this last printed. Used to refresh page
unsigned long timeLastPrinted = -1;
void* ItemRef = NULL;
String blnTrueTxt = "";
String blnFalseTxt = "";
//functions
public:
//Over-ridden base class functions
String Text(void) const override;
boolean isSelectable() const override { return false; };
void Select(EZUI *UI) const override { /* Do nothing */ };
//Destructor
~EZUI_Control_Label() override {};
//Instantiate - Static Values
EZUI_Control_Label(char val[]);
//EZUI_Control_Label(const char val[]);
//Instantiate - Dynamic Values
EZUI_Control_Label(float *val);
EZUI_Control_Label(double *val);
EZUI_Control_Label(int *val);
EZUI_Control_Label(unsigned int *val);
EZUI_Control_Label(long *val);
EZUI_Control_Label(unsigned long *val);
EZUI_Control_Label(boolean *val, String TrueText, String FalseText);
EZUI_Control_Label(DigitalIO *val);
protected:
private:
//EZUI_Control_Label( const EZUI_Control_Label &c );
//EZUI_Control_Label& operator=( const EZUI_Control_Label &c ) override;
}; //EZUI_Control_Lablel
#endif //__EZUI_CONTROL_LABLEL_H__
谢谢大家的帮助。这是一个循环引用问题,我EZUI_Control_Label添加了前向类声明类,问题消失了。再次感谢。
我还删除了UI_SHARED命名空间,因为我确定它不是我想要完成的任务所必需的。 不幸的是,我没有使用前向声明和共享命名空间重新测试,但我相信我问题的根源是找不到类声明。
相关文章:
- 将系数存储在头文件的数组中("does not name a type"错误)
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 如何解决"'mutex' in namespace 'std' does not name a type"?
- 在 C++ 中使用命名空间时出现"does not name a type"错误
- 已声明时"Does not name a type"错误
- 嵌套类"does not name a type"
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- Eigen loadMarket does not compile
- 为什么当我的代码超出函数范围时,"does not name a type"出现编译器错误?
- 创建C++ Redis 模块 - "does not export RedisModule_OnLoad() symbol"
- 无法分隔标头类。我得到"does not name a type"
- 模板元编程:"does not have integral or enumeration type"
- 如何修复类函数"prototype does not match"和"cadidate is"错误
- #define 的"Declaration does not declare anything"错误
- 修复第三方代码:"error: ‘enable_if’ in namespace ‘std’ does not name a template type"
- 在 c++ 中,如果包含标头,为什么我会收到'does not a name of type'错误?
- 什么原因导致我的"‘FatalError’ in namespace ‘Foam’ does not name a type"错误?
- C++ 迭代器错误"does not refer to a value"
- 编译错误"String does not name a type"