这段代码用gcc编译有错误
template<typename>
struct B {
};
template<typename... Types>
struct A : public B<Types>... {
using B<Types>::B...;
using B<Types>::operator=...;
}
Run Code Online (Sandbox Code Playgroud)
编译器输出
<source>:8:8: error: expected nested-name-specifier before 'B'
8 | using B<Types>::operator=...;
|
^
Run Code Online (Sandbox Code Playgroud)
但是这段代码编译没有错误
template<typename>
struct B {
};
template<typename... Types>
struct A : public B<Types>... {
using B<Types>::operator=...;
using B<Types>::B...;
};
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会发生这种情况。
更新
对于 gcc,构造函数继承也会破坏代码
template<typename T>
struct B {
void foo() {}
};
template<typename... Types>
struct A : public B<Types>... {
using B<Types>::B...;
void bar() {
(B<Types>::foo() , ...);
}
};
Run Code Online (Sandbox Code Playgroud)
这是一个 GCC 错误,最终在 GCC 11 中修复。
演示: https: //gcc.godbolt.org/z/arxjPjTa5
另一个演示: https: //gcc.godbolt.org/z/KhjGn945G
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |