Reputation: 21
I'm getting a error when compiling 'error: expected nested-name-specifier before"
The code is
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 ;
}
I'm using Ubuntun 12.04, GCC 4.6, and CodeBlocks 10.05
Upvotes: 1
Views: 14338
Reputation: 1
Not because of the header file, maybe because the c++ version is not c++11(try setting the compilation option to -std=c++11)
Upvotes: 0
Reputation:
I created this in a file:
#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;
}
and using g++ -std=c++11 program_name.cc it compiled and ran without any problem.
Upvotes: 3
Reputation: 339
Perhaps you meant the following:
typedef std::pair<float,float> range;
Remember to use C++11 (or you will get the warning: extended initializer lists only available with -std=c++11 or -std=gnu++11)
Upvotes: 2
Reputation: 173
Try this:
#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;
}
Upvotes: 1