c++ - Properly defining namespaces with anonymous functions -


i'm bit confused c++ namespaces, , how define them. have 2 files: lua.h , main.cpp. lua.h contains following helpers running lua scripts in namespace:

#ifndef lua_h #define lua_h  #include <lua.hpp>  namespace fabric {   namespace lua   {     void loadlibs(lua_state * l)     {       static const lual_reg lualibs[] =       {         { "io", luaopen_io },         { "base", luaopen_base },         { null, null }       };        const lual_reg * lib = lualibs;       (; lib->func != null; lib++)       {         lib->func(l);         lua_settop(l, 0);       }     }      void init(lua_state * l)      {       loadlibs(l);       lual_dofile(l, "init.lua");        lua_close(l);     }   } }  #endif 

my main.cpp files tries run lua script using these helper functions:

#include "lua.h"  int main (int argc, char * argv[]) {   fabric::lua::init();   return 0; } 

but when try compile main.cpp, this:

source/main.cpp:9:3: error: use of undeclared identifier 'fabric'   fabric::lua::init();   ^ 

i'm confused on how define namespace. code helper functions good, main.cpp can't find namespace. can give me pointers on how define namespace correctly in c++?

edit:

works now. reason -i flag wasn't working on compile since had headers under include/. renamed lua.h luahelpers.h.

i guess there's conflict between lua.h , lua's lua.h. consider renaming file fabric.h or that.

that said, putting non-inline functions header file cause linker errors when file included 2 translation units. consider splitting code typical header/implementation pair.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -