C++ Templates中的例子编译不过的原因

 此例子来源于《C++Templates The Complete Guide》,
使用了两种编译器(gcc 3.4.4, Dev-C++ 4.9.9.2),都出现如下错误:

C++ Templates中的functor源代码。编译其中的一个cpp文件(compose6.cpp)即可。
下载地址:
[url]http://www.josuttis.com/tmplbook/examples.zip[/url]

编译错误:
dell@dell
- PC / cygdrive / g / cyghome / src / cpptemplates / functors $ make g ++ .exe  compose6.cpp - o test.exe
In file included from forwardparam.hpp:
15 ,
                 from functionptr.hpp:
11 ,
                 from funcptr.hpp:
11 ,
                 from compose6.cpp:
12 :
typet.hpp:
73 : error: expected primary - expression before ' > ' token
typet.hpp: In instantiation of `IsFunctionT
< double > ' :
typet.hpp: 105 :   instantiated from `CompoundT < double > '
typet.hpp: 290 :   instantiated from `TypeT < double > '
forwardparam.hpp: 29 :   instantiated from `ForwardParamT < double > '
functionptr.hpp: 39 :   instantiated from `FunctionPtr < double , double , double , voi
d
> '
compose6.cpp: 29 :   instantiated from here
typet.hpp:
73 : error: enumerator value for `Yes ' not integer constant
make: *** [test.exe] Error 1
  
  
  
  
解决方法:去掉IsFunctionT<T>::
//enum { Yes = sizeof(IsFunctionT<T>::test<T>(0)) == 1 };  
  //error: expected primary-expression before '>' token
     enum { Yes = sizeof(test<T>(0)) == 1 };

你可能感兴趣的:(C++,编译,templates,休闲)