静态地图初始化函数错误 [英] Static map initializer function error

查看:97
本文介绍了静态地图初始化函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下基本错误:

1> c:\ program files \ Microsoft Visual Studio 10.0 \ vc \ include \ utility(163):错误C2436:"second":构造函数初始化器列表中的成员函数或嵌套类

1>c:\program files\microsoft visual studio 10.0\vc\include\utility(163): error C2436: 'second' : member function or nested class in constructor initializer list

以及那里的许多子错误-我根本不知道在哪里看或哪里出了问题. (我知道它的功能是什么,但是我一直盯着自己为什么不起作用)

As well as a lot of sub-errors there - I have no idea at all where to look or what goes wrong. (I know what functions it is about, but I'm staring myself blind on why it doesn't work)

标题部分:

typedef void *DuplicateFn(pTree&, const pTree&); 
enum DuplicateTy {
    SKIP,
    OVERWRITE,
    ASK
};
typedef std::map<DuplicateTy, DuplicateFn> DuplicateMapTy;

static const DuplicateMapTy DuplicateFns;
static DuplicateMapTy DuplicateFns_INIT();

详细名称空间:

namespace detail {
    void OverWriteFn(GMProject::pTree& tOut, const GMProject::pTree& tIn);
    void AskFn(GMProject::pTree&  tOut, const GMProject::pTree& tIn);
}

源部分:

GMProject::DuplicateMapTy GMProject::DuplicateFns_INIT() {
    DuplicateMapTy tmp;
    auto p(std::make_pair(GMProject::OVERWRITE, &detail::OverWriteFn));
    tmp.insert(p); //offending line
    return tmp;
}
const GMProject::DuplicateMapTy GMProject::DuplicateFns(GMProject::DuplicateFns_INIT());

如前所述,我对此视而不见,为什么我不能将那对插入地图?我只是插入一个函数指针&一个枚举?

As said I'm staring myself blind on this, why can't I insert that pair into the map? I'm simply inserting a function pointer & an enum?

推荐答案

我可能是错的,但是我不喜欢这行:

I might be wrong, but I don't like the line:

auto p(std::make_pair(GMProject::OVERWRITE, &detail::OverWriteFn));

您是否正在使用VS 2010?您可以将鼠标悬停在变量名称(p)上,并查看得出的是auto类型.

Are you using VS 2010? You can hover the variable name (p) and see which type auto has deduced.

另外,您是否尝试过:

 tmp.insert(std::make_pair(GMProject::OVERWRITE, &detail::OverWriteFn));

tmp.insert(std::pair(GMProject::OVERWRITE, &detail::OverWriteFn));

?

这篇关于静态地图初始化函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆