C ++ 11 decltype和auto关键字 [英] C++11 decltype and auto keywords
本文介绍了C ++ 11 decltype和auto关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要使用VC11构建以下内容
I have the following which I''m trying to build with VC11
struct Message
{
void Process();
};
struct Builder
{
Message* Build() const {return new Message();}
};
template <typename BuilderT>
auto MakeAndReturn(const BuilderT& builder) -> decltype(BuilderT.Build())
{
auto obj = builder.Build();
return obj;
}
void Test()
{
Builder builder;
auto message = MakeAndReturn(builder);
}
但我从Test()的最后一行得到了此编译器错误
but I get this compiler error from the final line in Test()
1>y:\repo\cpp11\test\auto.cc(152): error C2893: Failed to specialize function template ''''unknown-type'' MakeAndReturn(const BuilderT &)''
1> With the following template arguments:
1> ''Builder''
1>y:\repo\cpp11\test\auto.cc(152): fatal error C1903: unable to recover from previous error(s); stopping compilation
谁能解释原因?
Can anyone explain why?
推荐答案
我发现了问题
I found the problem
auto MakeAndReturn(const BuilderT& builder) -> decltype(BuilderT.Build())
应该是
should be
auto MakeAndReturn(const BuilderT& builder) -> decltype(builder.Build())
这篇关于C ++ 11 decltype和auto关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文