2011-10-22 124 views
2

此代码与Visual C++ 11 Developer Preview编译良好,但不会使用gcc 4.6.1进行编译。升级或不升级 - 这是questiion

如何使后者“可编译”?

#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

更改您的include指令:

#include <boost/mpl/vector.hpp> 

这将工作都在Windows和Unix类系统。

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

编辑:你在主要添加的东西,它编译与GCC 4.6.1。
别忘了#include <typeinfo>

+0

很好的发现,我永远不会记得哪个斜杠是'正确的'。现在确实有效。谢谢。 – smallB

+0

你会经常在Windows上使用'/',但在基于Unix的系统上,你基本上从不会使用任何工具来使用\。 (顺便说一句,包含指令是如何处理的,我相信是实现定义的,所以都不是安全的。) – Mat