c++ - 类模板特化的前向声明

标签 c++ templates

在类模板特化阶段,以下前向声明是合法的 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/

相关文章:

javascript - Angular 的编译不起作用

c++ - 将 PIMPL 习惯用法与成员函数模板一起使用(事先不知道所有可能的数据类型)

HTML 电子邮件模板

javascript - 如何在 underscore.js 模板中使用 if 语句?

java - 从 Jenkins 的邮件中发送 SonarQube 链接

c++ - Code::blocks 提示参数类型

c++ - 在谷歌模拟中捕获回调的参数

c++ - 如何将基类指针数组转换为派生类

c++ - 提升 IPC 字符串长度段错误?

c++ - 如何 "skip"某些子类函数