2

此代码在 Visual C++ 11 Developer Preview 中编译得很好,但在 gcc 4.6.1 中无法编译。

如何使其对后者“可编译”?

#ifndef PROMOTE_H_INCLUDED
#define PROMOTE_H_INCLUDED
#include <boost\mpl\vector.hpp>
#include <boost\mpl\find.hpp>
#include <boost\mpl\next.hpp>
#include <boost\mpl\deref.hpp>

namespace mpl =  boost::mpl;
template<class Integral>
struct Promote
{
    typedef  mpl::vector<char,short,int,long,long long> types;
    typedef typename  mpl::find<types,Integral>::type this_type;
    typedef typename  mpl::next<this_type>::type next_type;
    typedef typename  mpl::deref<next_type>::type type;
};
#endif // PROMOTE_H_INCLUDED  

然后主要是:

cout << typeid( Promote<int>::type).name() ;
4

1 回答 1

4

更改包含指令:

#include <boost/mpl/vector.hpp>

这适用于 Windows 和 Unix 类型的系统。

没有检测到其他语法问题(但由于这只是一个模板,我不知道你实际使用它时是否有问题)。

编辑:使用您在主中添加的内容,它可以使用 GCC 4.6.1 进行编译。
别忘了#include <typeinfo>

于 2011-10-22T10:23:56.130 回答