我最近将一个类从模板改为不,并发现在编写using声明从模板化基类继承构造函数时,我不能再省略模板参数 . 只要我的 class 不是't templated I can omit the arguments, as soon as it is I can' t . 在下面的可编辑片段中, bar
表示之前的类,而 buzz
表示之后的类 . 我测试了GCC 5.2和Clang 3.7,它们具有相同的行为 . 这是编译器错误还是标准?
#include <iostream>
template<class A, class B>
struct foo {
foo(int x) {
std::cout << x << std::endl;
}
};
struct bar : foo<bar, short> {
using foo::foo; // this appears legal
// using foo<bar, short>::foo; // this works too, thought I would need it
};
template<class X>
struct buzz : foo<buzz<X>, short> {
//using foo::foo; // no longer legal for some reason
using foo<buzz<X>, short>::foo; // now do actually need this
};
int main() {
bar x(3);
buzz<float> y(5);
return 0;
}
1 回答
这是标准的 .
对于
buzz
,基类依赖于模板参数,因此foo
非限定查找不会检查其范围 . 这就是您需要合格查找的原因 .