预期的嵌套名称说明符 - gcc

时间:2011-10-15 14:15:42

标签: c++ gcc4

在此代码中:

Int.h:

#include <type_traits>


#include "Best_Fit.h"
template<class Int_T, typename Best_Fit<Int_T>::type Min_Range,typename Best_Fit<Int_T>::type Max_Range>
class Int_Core
{//If I move this class to a separate header I'm getting aforementioned error

};

template<class Int_T, typename Best_Fit<Int_T>::type Min_Range, typename Best_Fit<Int_T>::type Max_Range>
class Int : private Int_Core<Int_T,Min_Range,Max_Range>
{

};

Best_Fit.h:

struct Signed_Type
{
    typedef long long type;
};

struct Unsigned_Type
{
    typedef unsigned long long type;
};

template<bool Cond, class First, class Second>
struct if_
{
    typedef typename First::type type;
};

template<class First, class Second>
struct if_<false,First,Second>
{
    typedef typename Second::type type;
};

template<class Int_T>
struct Best_Fit
{
    typedef typename if_<std::is_signed<Int_T>::value,Signed_Type,Unsigned_Type>::type type;
};  

main.cpp中:

#include <iostream>

using namespace std;

#include "Int.h"

int main(int argc, char* argv[])
{
    return 0;
}

错误:

error: expected nested-name-specifier before 'Best_Fit'|  

我用gcc 4.6.1编译它 是否有任何理由无法将Int_Core置于单独的标题中?

1 个答案:

答案 0 :(得分:0)

这可能根本没用,但我正在使用以下版本的g ++编译这个:

g++ --version 
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

使用以下命令:

g++ main.cpp -std=c++0x -o main

没有-std = c ++ 0x我得到错误“expected nested-name-specifier”