c++ - Two Namespace need each other -


how write namespace need each other? this:

namespace amxe {     void register(amx *amx);     void release(amx *amx);     struct s_amxe     {         command::s_command command;     };     extern std::unordered_map<amx*, s_amxe*> *list; }  namespace command {     extern dword onplayercommandtext_addr;      void initialize();     void registerallfromamx(amx* amx, amxe::s_amxe* amxdata);     cell command_addaltnamed_n(amx *amx, cell *params);     struct s_command     {         int onplayercommandreceived;         int onplayercommandperformed;     }; } 

when compile code, got warning command not namespace in "command::s_command command;" line.

the definition of command::s_command not available when use:

struct s_amxe {     command::s_command command; }; 

it makes sense compiler throws error @ line.

you can forward declare names (classes, functions, etc.) inside namespaces can forward declare global names.

after can use pointers , references types. however, use object of class in namespace, class must defined first.

also, remember that, unlike classes, namespaces can divided multiple blocks.

you can reorganize code shown below:

// define command::s_command first. namespace command {    struct s_command    {       int onplayercommandreceived;       int onplayercommandperformed;    }; }  namespace amxe {    void register(amx *amx);    void release(amx *amx);    struct s_amxe    {       command::s_command command;    };    extern std::unordered_map<amx*, s_amxe*> *list; }  // define rest of command namespace namespace command {    extern dword onplayercommandtext_addr;     void initialize();    void registerallfromamx(amx* amx, amxe::s_amxe* amxdata);    cell command_addaltnamed_n(amx *amx, cell *params); }