64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
template <typename type1 = int ,
typename type2 = char >
class A
{
};
template <typename type1= int,
typename type2 = A> // !!!!!!!!!!!!!!!!!!!!
struct B
{
public:
void test()
{
std::cout << "---" << typeid( type2 ).name() << std::endl;
}
};
int main()
{
B<int> cb;
cb.test();
return 0;
}
// aaa.cpp(22) : error C3203: “A”: 未专用化的类 模板 不能用作 模板 变量,该变量属
// 于 模板 参数“type2”,应为 real 类型
template <typename type1= int,
typename type2 = A <> > // !!!!!!!!!!!!!!!!!!!!
struct B
int main()
{
B cb;
cb.test();
return 0;
}
// aaa.cpp(22) : error C2955: “B”: 使用类 模板 需要 模板 参数列表
// aaa.cpp(18) : 参见“B”的声明
// aaa.cpp(22) : error C2133: “cb”: 未知的大小
// aaa.cpp(22) : error C2512: “B”: 没有合适的默认构造函数可用
// aaa.cpp(23) : error C2662: “B<type1,type2>::test”: 不能将“this”指针从“B”转
// 换为“B<type1,type2> &”
// 原因如下: 无法从“B”转换为“B<type1,type2>”
// 转换要求第二个用户定义的转换运算符或构造函数
int main()
{
// 声明B时使用空的模板参数即可
B<> cb;
cb.test();
return 0;
}