【发布时间】:2016-02-17 18:46:22
【问题描述】:
我最近将一个类从模板化改为非模板化,并发现在编写 using 声明以从模板化基类继承构造函数时,我不能再省略模板参数。只要我的课程没有模板化,我就可以省略参数,一旦它是我不能。在下面的可编译 sn-p 中,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;
}
【问题讨论】:
标签: c++ templates g++ c++14 clang++