且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-09-16 14:43:08

 此例子来源于《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<doubledoubledouble, 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>::
C++ Templates中的例子编译不过的原因//enum { Yes = sizeof(IsFunctionT<T>::test<T>(0)) == 1 };  
  //error: expected primary-expression before '>' token
C++ Templates中的例子编译不过的原因    enum { Yes = sizeof(test<T>(0)) == 1 };
C++ Templates中的例子编译不过的原因












本文转sinojelly51CTO博客,原文链接:http://blog.51cto.com/sinojelly/99368,如需转载请自行联系原作者