Hello,
I'm doing some toy experiments to see how
the algoritm std::transform and the function
adapter std::bind2nd can play together, but
my compiler give my the error
error: passing `const traslate' as `this' argument of
`circle traslate::operator()(circle, std::vector<double,
std::allocator<double)'
discards qualifiers
It should be like I'm trying to modify
something which is declared as const...
The example code follows.
I define the type `circle', which holds
center and radius of a circle, then I
introduce a vector of circles and try to
traslate them all with std::transform.
I need std::bind2nd to fix the traslation
for all the circles.
Note that I'm forced to define the
temporary object `traslate' to meet
std::bind2nd input specifications.
// =======================================
#include <vector>
#include<functional>
#include<algorithm>
using namespace std;
struct circle
{
vector<doublecenter;
double radius;
};
struct traslate
{
typedef circle first_argument_type;
typedef vector<doublesecond_argument_type;
typedef circle result_type;
circle operator()(const circle original, const vector<double>
traslation)
{
circle traslated = original;
traslated.center[0] += traslation[0];
traslated.center[1] += traslation[1];
return traslated;
}
};
int main()
{
vector<circlelots_of_circles(10);
vector<circlesome_other_circles(10);
vector<doubletraslation(2);
traslation[0] = 123;
traslation[1] = 321;
transform(lots_of_circles.begin(), lots_of_circles.end(),
some_other_circles.begin(), bind2nd(traslate(), traslation));
}
// =======================================
Can you see the reason of the above mentioned error?
Regards,
Giovanni Gh.