代码之家  ›  专栏  ›  技术社区  ›  SusgUY446

访问嵌套命名空间C外的元素时出现问题++

  •  0
  • SusgUY446  · 技术社区  · 5 月前

    我的整个项目都有一个很大的命名空间,然后每个组件(文件)在该文件中都有自己的嵌套命名空间。大命名空间称为IEEngine,嵌套命名空间称为IEAewever(例如IEWindow)。但是,我该如何从IEEngine::IEWhatever2访问IEEngine::IEWhatever2。当我执行IEEngine::IEWhatever::Something时,我收到一个错误,即命名空间IEEngine中没有成员IEWhatever。我包含了提供名称空间IEWWhatever的文件。但是该文件还包括提供IEWhatever2的文件,因此它错误地说IEWhatever未定义(include放在IEWhatever1命名空间之前)。我该如何修复这个IE?有些东西也不起作用。我也试过了 使用Something=IE Whatever:某物;但那行不通

    IEDisplay.hpp:

    #ifndef IEDISPLAY_HPP
    #define IEDISPLAY_HPP
    
    #ifndef IEWINDOW_HPP
    #include "IEWindow.hpp"
    #endif // IEWINDOW_HPP
    
    
    #include <wayland-client.h>
    #include <wayland-cursor.h>
    
    #include "external/wayland-protocols/tearing-control-v1/tearing-control-v1.h"
    #include "external/wayland-protocols/xdg-shell/xdg-shell-client-protocol.h"
    #include "external/wayland-protocols/viewporter/viewporter-client-protocol.h"
    
    
    
    namespace IEEngine {
        namespace IEDisplay {
            class WLDisplay {   
                private:
                    struct wl_display* display;
                    struct wl_registry* registry;
                    struct wl_compositor* compositor;
                    struct xdg_wm_base* wm_base;
                    struct wl_seat* seat;
                    struct wl_pointer* pointer;
                    struct wl_touch* touch;
                    struct wl_keyboard* keyboard;
                    struct wl_shm* shm;
                    struct wl_cursor_theme* cursor_theme;
                    struct wl_cursor* cursor;
                    struct wl_surface* cursor_surface;
                    struct wp_tearing_control_manager_v1* tearing_manager;
                    struct wp_viewporter* viewporter;
                    struct wp_fractional_scale_manager_v1* fractional_scale_manager;
                    IEWindow::WLWindow window;
            };
        }
    }
    
    
    #endif // IEDISPLAY_HPP
    

    IEWindow.hpp:

    #ifndef IEWINDOW_HPP
    #define IEWINDOW_HPP
    
    
    
    
    #ifndef IEDISPLAY_HPP
    #include "IEDisplay.hpp"
    #endif // IEDISPLAY_HPP
    
    namespace IEEngine {
        namespace IEWindow {
            class WLWindow {    
                IEDisplay::WLDisplay display;
                int wHeight;
                int wWidth;
            };
        }
    }
    
    
    
    #endif // IEWINDOW_HPP
    
    1 回复  |  直到 5 月前
        1
  •  1
  •   Rud48    5 月前

    根据提供的代码,您需要为添加一个前向声明 WLDisplay. 这是一个省略了大部分细节的缩写版本。

    namespace IEEngine {
       namespace IEWindow {
          class IEDisplay::WLDisplay; // <<== added
          class WLWindow { 
             /*...*/
             IEDisplay::WLDisplay display;
          };
       }
    }
    
    namespace IEEngine {
       namespace IEDisplay {
          class WLDisplay {
          private:
             IEWindow::WLWindow& window;
             /*...*/
          };
       }
    }
    

    另请注意参考文献的使用 IEWindow::WLWindow& window 在里面 WLDisplay 因为我怀疑你真的不想把这门课也包括在内。