[quote=引用 6 楼 hzh_0000 的回复:] [quote=引用 5 楼 hai200501019 的回复:] 不是是注释的错吧。Noncomparable类没有定义 == 操作符,所以才报错吧。下面的是个模板,你没有实例化,没有调用SoftLogic 的compare函数的时候是肯定不会报错的。 class Noncomparable { }; class HardLogic { Noncomparable nc1,nc2; /* void compare() { nc1 == nc2; }*/ }; template <class T> struct SoftLogic { Noncomparable nc1,nc2; void compare() { nc1 == nc2; } }; int main() { SoftLogic<Noncomparable> soft1; soft1.compare(); system("pause"); return 0; } 这样你编译就会发现一样是编译出错
[quote=引用 5 楼 hai200501019 的回复:] 不是是注释的错吧。Noncomparable类没有定义 == 操作符,所以才报错吧。下面的是个模板,你没有实例化,没有调用SoftLogic 的compare函数的时候是肯定不会报错的。 class Noncomparable { }; class HardLogic { Noncomparable nc1,nc2; /* void compare() { nc1 == nc2; }*/ }; template <class T> struct SoftLogic { Noncomparable nc1,nc2; void compare() { nc1 == nc2; } }; int main() { SoftLogic<Noncomparable> soft1; soft1.compare(); system("pause"); return 0; } 这样你编译就会发现一样是编译出错
不是是注释的错吧。Noncomparable类没有定义 == 操作符,所以才报错吧。下面的是个模板,你没有实例化,没有调用SoftLogic 的compare函数的时候是肯定不会报错的。 class Noncomparable { }; class HardLogic { Noncomparable nc1,nc2; /* void compare() { nc1 == nc2; }*/ }; template <class T> struct SoftLogic { Noncomparable nc1,nc2; void compare() { nc1 == nc2; } }; int main() { SoftLogic<Noncomparable> soft1; soft1.compare(); system("pause"); return 0; } 这样你编译就会发现一样是编译出错
无后效性语句,没有用的。
不懂,是模板起了作用吗?
64,683
社区成员
250,491
社区内容
加载中
试试用AI创作助手写篇文章吧