error: incomplete type ‘’ used in nested name specifier

error: incomplete type ‘’ used in nested name specifier

内容

出现这个错误的原因是:

在A.h中定义了一个类模版,并且在A.h中需要#include “B.h”(即,需要知道B的定义)
而在B.h中又使用了A.h中定义的模版,因此也需要#include “A.h”(即,又需要知道A的定义)

头文件相互包含,不但要用到#include,而且还要分别声明要用到的类。
比如A.h中,添加#include"B.h",而且要添加class B;B.h中也是一样,否则就报错。

本人机器开发环境

  • ubuntu 16.04
  • CLion 2018

相关/参考链接

https://www.cnblogs.com/justinyo/archive/2013/02/19/2917631.html