我的问题与
非常相似Apache module command parser prototype
但是,我在apr_cmd []中有更多初始化,即我有类似
的东西 static const command_rec apr_cmds[] =
{
AP_INIT_TAKE1("analytics_ip", apr_cfg_set_analytics_ip, NULL, OR_ALL, ""),
AP_INIT_TAKE1("AuthenDenied", set_authen_denied, (void*)APR_OFFSETOF(config_rec, authen_denied), OR_AUTHCFG, ""),
AP_INIT_FLAG("RefreshCookies", ap_set_flag_slot, (void*)APR_OFFSETOF(config_rec, refresh_cookies), OR_AUTHCFG, ""),
{ NULL }
};
对于每次初始化,我得到了#34;无法转换为cmd_func"编译错误。
Krystof建议使用
#ifdef __cplusplus
typedef const char *(*cmd_func) (cmd_parms *cmd, void *dummy, const char *path);
#else
typedef const char *(*cmd_func) ();
#endif
如果我这样做,第一个错误就会消失。但是,其他错误仍然存在,因为我无法再次为第二个函数set_authen_denied重新定义cmd_func。
感谢任何帮助。
答案 0 :(得分:0)
删除黑客代码并生成工厂功能。
namespace cmd_func_type{
/** function to call for a no-args */
using no_args_t = const char *(*) (cmd_parms *parms, void *mconfig);
/** function to call for a raw-args */
using raw_args_t = const char *(*) (cmd_parms *parms, void *mconfig, const char *args);
/** function to call for a argv/argc */
using take_argv_t = const char *(*) (cmd_parms *parms, void *mconfig, int argc, char *const argv[]);
/** function to call for a take1 */
using take1_t = const char *(*) (cmd_parms *parms, void *mconfig, const char *w);
/** function to call for a take2 */
using take2_t = const char *(*) (cmd_parms *parms, void *mconfig, const char *w, const char *w2);
/** function to call for a take3 */
using take3_t = const char *(*) (cmd_parms *parms, void *mconfig, const char *w, const char *w2, const char *w3);
/** function to call for a flag */
using flag_t = const char *(*) (cmd_parms *parms, void *mconfig, int on);
}
template<cmd_how args_how = NO_ARGS>
cmd_func make_cmd_func(cmd_func_type::no_args_t f){ cmd_func re; re.no_args = f; return re; }
template<cmd_how args_how = NO_ARGS> cmd_func make_cmd_func(cmd_func_type::raw_args_t);
template<>
cmd_func make_cmd_func<RAW_ARGS>(cmd_func_type::raw_args_t f){ cmd_func re; re.raw_args = f; return re; }
template<cmd_how args_how = TAKE_ARGV>
cmd_func make_cmd_func(cmd_func_type::take_argv_t f){ cmd_func re; re.take_argv = f; return re; }
template<>
cmd_func make_cmd_func<TAKE1>(cmd_func_type::take1_t f){ cmd_func re; re.take1 = f; return re; }
template<cmd_how args_how = TAKE2>
cmd_func make_cmd_func(cmd_func_type::take2_t f){ cmd_func re; re.take2 = f; return re; }
template<cmd_how args_how = TAKE3>
cmd_func make_cmd_func(cmd_func_type::take3_t f){ cmd_func re; re.take3 = f; return re; }
template<cmd_how args_how = FLAG>
cmd_func make_cmd_func(cmd_func_type::flag_t f){ cmd_func re; re.flag = f; return re; }
template<
cmd_how args_how, typename DataPtr, typename CmdFuncType,
std::enable_if_t<std::is_pointer<DataPtr>::value || std::is_same<DataPtr, std::nullptr_t>::value, std::nullptr_t> = nullptr
>
command_rec make_command_rec(const char *name, CmdFuncType f, DataPtr cmd_data, int req_override, const char *errmsg){
return {name, make_cmd_func<args_how>(f), (void*)(cmd_data), req_override, args_how, errmsg };
}