iedstruct 2022-08-10 15:43 采纳率: 50%
浏览 58
已结题

加了ifndef头文件互相包含仍报错

有两个文件代码,一个aa.h,一个bb.h,如下:

//aa.h



#ifndef _AA_H_

#define _AA_H_

//#include"bb.h"  //这行代码出问题

template<class T1,class T2>
T1 cvtType(T2 x)
{

}


#endif
//bb.h

#ifndef _BB_H_
#define _BB_H_

#include"aa.h"

template<class T>
void func(T x)
{
    cvtType<std::string>(x);
}

#endif

如果加上include"bb.h"就会报错如下:

 

如果不加上就能编译成功。 虽然说删掉include"bb.h"就能解决问题,但是我还是想了解一下背后的原因。 已经加上了ifndef,为什么还是报错。 求解答。
  • 写回答

3条回答 默认 最新

  • 乐观的study123 2022-08-10 16:07
    关注

    因为BB里边调用了 cvtType(x);这个函数

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月10日
  • 创建了问题 8月10日