Reputation: 55
I used this line code in VC++2012 to sort integrated row array called arrayCosts. This code work in this version but d not work at VC++6 version.
vector< vector<float> > my_vector ;
for( const auto& row : arrayCosts ) my_vector.push_back( vector<float>( begin(row), end(row) ) ) ;
sort( begin(my_vector), end(my_vector),
[]( const vector<float>& a, const vector<float>& b ) { return a[1] < b[1] ; } ) ;
The errors in VC++6 is as following.
e:\logistics\projects\10\10\source1.cpp(190) : error C2143: syntax error : missing ',' before ':'
e:\logistics\projects\10\10\source1.cpp(190) : error C2530: 'row' : references must be initialized
e:\logistics\projects\10\10\source1.cpp(190) : error C2059: syntax error : ':'
e:\logistics\projects\10\10\source1.cpp(191) : error C2065: 'begin' : undeclared identifier
e:\logistics\projects\10\10\source1.cpp(191) : error C2065: 'end' : undeclared identifier
e:\logistics\projects\10\10\source1.cpp(192) : error C2059: syntax error : '['
e:\logistics\projects\10\10\source1.cpp(192) : error C2143: syntax error : missing ')' before '{'
e:\logistics\projects\10\10\source1.cpp(192) : error C2143: syntax error : missing ';' before '{'
e:\logistics\projects\10\10\source1.cpp(192) : error C2065: 'a' : undeclared identifier
e:\logistics\projects\10\10\source1.cpp(192) : error C2109: subscript requires array or pointer type
e:\logistics\projects\10\10\source1.cpp(192) : error C2065: 'b' : undeclared identifier
e:\logistics\projects\10\10\source1.cpp(192) : error C2109: subscript requires array or pointer type
Upvotes: 1
Views: 232
Reputation: 254681
You're trying to use language features from 2011 with a compiler from 1997. That's not going to work.
You might have more success if you stick to C++98; although since your compiler predates even that, there's no guarantee that this would work.
// Define a comparison functor, to replace the lambda.
// This must be defined outside a function, for arcane reasons.
struct comparator {
bool operator()(const vector<float>& a, const vector<float>& b) {
return a[1] < b[1];
}
};
vector< vector<float> > my_vector ;
// Use an old-school for loop; range-based loops didn't exist back then,
// and neither did "auto" type deduction.
// (This assumes arrayCosts is also a vector<vector<float>>;
// change the iterator type if it's something else).
for (vector< vector<float> >::const_iterator it = arrayCosts.begin();
it != arrayCosts.end(); ++it)
{
// std::begin and std::end didn't exist either
my_vector.push_back( vector<float>( it->begin(), it->end() ) ) ;
}
// Again, no std::begin or std::end.
sort(my_vector.begin(), my_vector.end(), comparator());
Upvotes: 4