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

发布于 2024-12-09 18:20:41 字数 1395 浏览 1 评论 0原文

在此代码中:

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 放在单独的标头中?

In this code:

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:

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

I'm compiling it with gcc 4.6.1
Any reason for not being able to place Int_Core in separate header?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咆哮 2024-12-16 18:20:41

这可能根本没有帮助,但我使用以下版本的 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 我收到错误“预期嵌套名称说明符”

This probably won't help at all, but I'm compiling this fine using the following version of 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.

with the following command:

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

Without the -std=c++0x I get the error "expected nested-name-specifier"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文