预期的嵌套名称说明符 - gcc
在此代码中:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能根本没有帮助,但我使用以下版本的 g++ 编译这个罚款:
使用以下命令:
如果没有 -std=c++0x 我收到错误“预期嵌套名称说明符”
This probably won't help at all, but I'm compiling this fine using the following version of g++:
with the following command:
Without the -std=c++0x I get the error "expected nested-name-specifier"