Re: [cpp] 关于模板

ling xl-yc-lzj at necsoft.com.cn
Mon Jul 31 15:12:07 CST 2006


明白了,多谢了。
----- Original Message ----- 
From: "Chen Shuo" <giantchen at gmail.com>
To: "C++ Discuss Group" <cpp at codingnow.com>
Sent: Monday, July 31, 2006 4:39 PM
Subject: Re: [cpp] 关于模板


模板函数在用到的时候才会instantiation.

On 7/31/06, ling <xl-yc-lzj at necsoft.com.cn> wrote:
>
> c++编程思想的一道习题,下面的代码中,
> HardLogic的compare函数会报错,但是SoftLogic的
> compare函数却不报错,这是为什么呢?
>
> class Noncomparable { };
>
> struct HardLogic {
>  Noncomparable nc1, nc2;
>  void compare() {
>   return nc1 = nc2;
>  }
> };
>
> template<class T> struct SoftLogic {
>  T nc1, nc2;
>  void noOp() {}
>  void compare() {
>   return nc1 = nc2;
>  }
> };
>
> int main()
> {
>  SoftLogic<Noncomparable> l;
>  l.noOp();
> }
>
> _______________________________________________
> Cpp mailing list
> Cpp at codingnow.com
> http://codingnow.com/mailman/listinfo/cpp
>
>

_______________________________________________
Cpp mailing list
Cpp at codingnow.com
http://codingnow.com/mailman/listinfo/cpp 




More information about the Cpp mailing list