作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何修复 using
行?
test_temp.cpp:
#include <memory>
template <typename A, typename B, template<typename> class C>
class X {};
template <typename A1, typename B1, template<typename> class C1>
class Type_bundle {
public:
typedef A1 A;
typedef B1 B;
template<typename T> using C = C1<T>;
};
template <typename T_b>
using X_b = X<typename T_b::A, typename T_b::B, typename T_b::template C>;
int main() {
typedef Type_bundle<int,float,std::allocator> Ttb;
X_b<Ttb> x;
}
来自 clang++ 的错误
test_temp.cpp:14:63: error: expected an identifier or template-id after '::'
using X_b = X<typename T_b::A, typename T_b::B, typename T_b::template C>;
~~~~~^
为什么这行不通?
最佳答案
当你写的时候:
template <typename T_b>
using X_b = X<typename T_b::A, typename T_b::B, typename T_b::template C>;
// ~~~~~~~~~
这表明后面将是一个类型的名称。但是T_b::template C
不是一个类型,它是一个模板,所以这个结构是无效的。如果您继续将参数传递给 C
,您将使用该构造, 比如 typename T_b::template C<D>
.那里,两个typename
和 template
是必要的。
你想要的只是:
template <typename T_b>
using X_b = X<typename T_b::A, typename T_b::B, T_b::template C>;
没有typename
.
关于c++ - 从类型包中解压模板模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42303674/
我是一名优秀的程序员,十分优秀!