iedstruct 2022-08-10 08:32 采纳率: 50%
浏览 38
已结题

类模板特化语法错误问题

出错代码如下:


//main.cpp

#include"aa.h"

int main()
{
    
    return 0;
}
//aa.h

#ifndef _AA_H_
#define _AA_H_

#include"bb.h"

template<class>
struct is_sned{};

#endif

//bb.h



#ifndef _BB_H_

#define _BB_H_

#include"aa.h"

template<>
struct is_sned<int>{};

#endif

vs报错:

img


这是什么问题?
另外,如果我把bb.h中模板特化的部分放到aa.h中,就发现不报错了。
其中的原因是什么?

  • 写回答

2条回答 默认 最新

  • 关注

    aa.h中包含了bb.h,而bb.h中又包含了aa.h,导致了循环嵌套。
    修改方法:
    把aa.h中的include "bb.h"删掉

    img

    如有帮助,望采纳,谢谢。

    img

    评论 编辑记录

报告相同问题?

问题事件

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