类模板特化语法错误问题

出错代码如下:


//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中,就发现不报错了。
其中的原因是什么?

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

img

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

img

特化的模板,一定要和泛化的模板放在一起,因为全特化与偏特化是要有泛化的基础上才能声明的,且参数的数量与泛化的一致