在命名空间内实例化时的 C++ "Does not name type"

c++ "Does not name type" when instantiating inside of namespace

本文关键字:Does not name type C++ 命名空间 实例化      更新时间:2023-10-16

我正在尝试使用命名空间来分割我的代码片段并重用一些名称。 当我创建一个新的命名空间时,编译器似乎失去了在该命名空间之外定义的类的范围。

我在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命名空间,因为我确定它不是我想要完成的任务所必需的。 不幸的是,我没有使用前向声明和共享命名空间重新测试,但我相信我问题的根源是找不到类声明。