在类模板特化阶段,以下前向声明是合法的 C++ 代码吗?
template<typename>
struct Basic
{};
template<>
struct Basic<struct Foo> //<-- Fwd declaration?
{};
struct Foo
{
Basic<Foo> m_a;
};
int main()
{
Foo test;
}
它does compile , 但我不确定这是否合法
最佳答案
template<>
struct Basic<struct Foo>
{};
是合法的。
来自 C++11 Standard :
A class declaration introduces the class name into the scope where it is declared and hides any class, variable, function, or other declaration of that name in an enclosing scope.
关于c++ - 类模板特化的前向声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48387958/