C++ 获取未赋值上下文中成员参数化函数的返回类型
给定以下代码(complexer代码的简化情况):C++ 获取未赋值上下文中成员参数化函数的返回类型,c++,templates,c++11,C++,Templates,C++11,给定以下代码(complexer代码的简化情况): #包括 模板 结构索引 { 使用类型=无效; }; 结构包 { 模板 静态类型名索引_st::type get(); 模板 使用unpack_t=decltype(get()); }; 模板 结构解包 { 使用type=typename P::unpack\u t; }; int main() { 打开u形包装; } gcc(4.8.1)引发以下编译错误: sample.cpp:21:38:错误:应为“;”在 进一步资料: 添加模板关键
#包括
模板
结构索引
{
使用类型=无效;
};
结构包
{
模板
静态类型名索引_st::type get();
模板
使用unpack_t=decltype(get());
};
模板
结构解包
{
使用type=typename P::unpack\u t;
};
int main()
{
打开u形包装;
}
gcc(4.8.1)引发以下编译错误:
sample.cpp:21:38:错误:应为“;”在
进一步资料:
添加模板
关键字:使用type=typename P::模板解包代码>@FilipRoséen refp再增加30张投票票,即可安装dup close@雅克实际上只需要再回答3个问题,计票更新缓慢;我正在努力!
#include <type_traits>
template<unsigned i>
struct index_st
{
using type = void;
};
struct pack
{
template<unsigned index>
static typename index_st<index>::type get();
template<unsigned index>
using unpack_t = decltype(get<index>());
};
template<typename P, unsigned index>
struct unpack
{
using type = typename P::unpack_t<index>;
};
int main()
{
unpack<pack, 3> u;
}
sample.cpp:21:38: error: expected ';' before '<' token
using type = typename P::unpack_t<index>;
^
sample.cpp:21:38: error: expected unqualified-id before '<' token
sample.cpp: In instantiation of 'struct unpack<pack, 3u>':
sample.cpp:26:21: required from here
sample.cpp:21:38: error: 'typename pack::unpack_t' names 'template<unsigned int index> using unpack_t = decltype (get<index>())', which is not a type
using type = typename P::unpack_t<index>;
using type = typename P::template unpack_t<index>;