A
alice
Hi all,
I am using the STL sort to a vector whose every element is an instance
type "struct data" as defined below:
However, when I am trying to compile the code, I am getting the
following error:
/usr/include/c++/3.4.3/bits/stl_algo.h:90: error: passing 'const
SerialNumbers::data' as 'this' argument of 'bool
SerialNumbers::data:perator<(const SerialNumbers::data&)' discards
qualifiers
Can anybody please explain to me what that error means?
I am using the g++ to compile my code.
The code follows:
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <sstream>
using namespace std;
class Test {
public:
struct data
{
string str;
bool operator < (const data& d2)
{
return false;
}
};
vector <string> sortSerials(vector <string> inp)
{
vector<data> table;
for(int i=0; i < inp.size(); ++i)
{
data d;
d.str = inp.at(i);
table.push_back(d);
}
sort(table.begin(),table.end());
vector<string> ret;
for(int i=0; i < table.size(); ++i)
{
ret.push_back(table.at(i).str);
}
return ret;
} // the method ends here.
};
I am using the STL sort to a vector whose every element is an instance
type "struct data" as defined below:
However, when I am trying to compile the code, I am getting the
following error:
/usr/include/c++/3.4.3/bits/stl_algo.h:90: error: passing 'const
SerialNumbers::data' as 'this' argument of 'bool
SerialNumbers::data:perator<(const SerialNumbers::data&)' discards
qualifiers
Can anybody please explain to me what that error means?
I am using the g++ to compile my code.
The code follows:
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <sstream>
using namespace std;
class Test {
public:
struct data
{
string str;
bool operator < (const data& d2)
{
return false;
}
};
vector <string> sortSerials(vector <string> inp)
{
vector<data> table;
for(int i=0; i < inp.size(); ++i)
{
data d;
d.str = inp.at(i);
table.push_back(d);
}
sort(table.begin(),table.end());
vector<string> ret;
for(int i=0; i < table.size(); ++i)
{
ret.push_back(table.at(i).str);
}
return ret;
} // the method ends here.
};