繁体   English   中英

模板的前向声明

[英]Forward declaration of template

我不喜欢将前向声明用作:

struct A;

struct B
{
   A* a;
}

// Implementation

我习惯做这样的事情:

struct B
{
   struct A* a;
}

但是,当我尝试使用模板类进行处理时遇到了问题:

template<typename T>
struct A
{
    struct B<T>* _t;
};

template<typename T>
struct B
{
    T _t;
};

编译器告诉我:

test.cpp:4:12: error: 'B' is not a template
test.cpp:8:8: error: 'B' is not a template type

我该如何实现?

两步。

步骤1:在结构A之前定义结构B

第2步:喜欢向前声明。

带有代码的双Vigneshwaren注释:模板struct B {T _t; };

template<typename T>
struct A
{
    struct B<T>* _t;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM