【发布时间】:2018-01-15 20:29:42
【问题描述】:
代码如下:
template <typename T, int P> struct _t_test_struct{
T t;
int p=P;
};
typedef _t_test_struct<float, 6> _test_struct6;
template <typename T, typename TP, TP P, template<typename, TP> class C>
void test1(C<T,P> &x){
std::vector<T> _a;
_a.resize(P);
_a[0] = x.t;
std::cout<<"typeid(P):"<<typeid(P).name()<<std::endl;
};
_test_struct6 _testp;
_testp.t = 10;
test1(_testp);
为什么编译器无法确定TP 是int?我只能称它为test1<float, int>(_testp)。
【问题讨论】:
-
在这里工作coliru.stacked-crooked.com/a/40999945ca7f280f。你遇到了什么错误?
-
@0x499602D2 - 因为您编译 C++17 而有效。但是 OP 将这个问题标记为 C++11。我想,如果你编译 C++11 或 C++14,你会得到一个编译错误。
标签: c++ c++11 templates template-argument-deduction