静态映射初始化函数错误
我收到以下基本错误:
1>c:\program files\microsoft Visual Studio 10.0\vc\include\utility(163): 错误 C2436: 'second' : 构造函数初始值设定项列表中的成员函数或嵌套类
以及那里的很多子错误 - I根本不知道该去哪里查看或出了什么问题。 (我知道它是关于什么功能的,但我对为什么它不起作用感到盲目)
标题部分:
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());
正如我所说,我对这一点感到盲目,为什么不能我将该对插入到地图中吗?我只是插入一个函数指针 &枚举?
I get the following base error:
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)
The header part:
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();
detail namespace:
namespace detail {
void OverWriteFn(GMProject::pTree& tOut, const GMProject::pTree& tIn);
void AskFn(GMProject::pTree& tOut, const GMProject::pTree& tIn);
}
The source part:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能是错的,但我不喜欢这句话:
Are you using VS 2010?您可以将鼠标悬停在变量名称 (
p
) 上并查看auto
推导了哪种类型。另外,您是否尝试过:
或者
?
I might be wrong, but I don't like the line:
Are you using VS 2010? You can hover the variable name (
p
) and see which typeauto
has deduced.Also, have you tried:
Or
?