错误:'xxx'之前应嵌套名称说明符
error: expected nested-name-specifier before 'xxx'
我在编译"错误:之前预期的嵌套名称说明符"时遇到错误
代码是
using range = std::pair<float,float> ;
range make_range( float a, float b ) { return { std::min(a,b), std::max(a,b) } ; }
bool intersects( range a, range b )
{
if( a > b ) std::swap(a,b) ;
return a.second >= b.first ;
}
我正在使用 Ubuntun 12.04、GCC 4.6 和 CodeBlocks 10.05
我在文件中创建了这个:
#include <utility>
#include <algorithm>
#include <iostream>
using range = std::pair<float,float> ;
range make_range( float a, float b ) { return { std::min(a,b), std::max(a,b) } ; }
bool intersects( range a, range b )
{
if( a > b ) std::swap(a,b) ;
return a.second >= b.first ;
}
int main()
{
float x =1.0;
float y =10.0;
range pair_1 = make_range( x, y);
range pair_2 = make_range(-2, 6);
bool brs = intersects( pair_1, pair_2 );
std::cout<<std::get<0>(pair_1)<<" "<<std::get<1>(pair_1)<<std::endl;
std::cout<<std::get<0>(pair_2)<<" "<<std::get<1>(pair_2)<<std::endl;
std::cout<<brs<<std::endl
return 0;
}
并使用 g++ -std=c++11 program_name.cc,它编译和运行没有任何问题。
也许你的意思是:
typedef std::pair<float,float> range;
请记住使用 C++11(否则您将收到警告:扩展初始值设定项列表仅适用于 -std=c++11 或 -std=gnu++11)
试试这个:
#include<tuple>
#include<algorithm>
using range = std::pair<float, float>;
range make_range(float a, float b) { return{ std::min(a, b), std::max(a, b) }; }
bool intersects(range a, range b)
{
if (a > b) std::swap(a, b);
return a.second >= b.first;
}
不是因为头文件,也许是因为 c++ 版本不是 c++11(尝试将编译选项设置为 -std=c++11)
相关文章:
- 在 CRTP 中使用嵌套名称说明符
- C++预期的嵌套名称说明符
- 缩短成员函数作用域说明符(嵌套类)(C++)
- C++:在嵌套名称说明符中命名的不完整类型
- 使用另一个模板类的嵌套名称说明符专用化模板类
- 在嵌套名称说明符中使用枚举(编译器警告)
- 详细说明的类型说明符中的类型相关嵌套名称说明符
- 编译器错误,应为嵌套的名称说明符
- 嵌套名称说明符中使用的类型不完整
- 错误:不完整的类型..在嵌套名称说明符中使用
- 类型名称关键字和嵌套名称说明符
- 编译器错误:typedef 之前的预期嵌套名称说明符
- 错误:'xxx'之前应嵌套名称说明符
- 正在解析循环依赖的嵌套类型说明符
- 嵌套名称说明符中第一个命名空间名称的名称查找
- 前向声明问题:嵌套名称说明符中使用的类型不完整'enums::Category'
- 嵌套名称说明符中使用的不完整类型,为什么?
- 预期的嵌套名称说明符- gcc
- 嵌套名称说明符中的不完整类型
- 使用子类作为基类的模板参数和嵌套名称说明符