S
suresh
Hi,
In my code, the operator() method of a function object is designed to
fill a set which is a private data member of the function object. This
function object is used in min_element algorithm.
Since the min_element algorithm uses a copy of the function object (as
per my understanding - hoping it to be true), I am unable to access
the set data member of the function object. A minimal code is show
below:
class FO{
public:
bool operator()(int a, int b);
private:
set<int> s;
};
bool FO:
perator()(int a,int b){
s.insert(a);
return (a<b);
}
vector<int> v;
//vector populated
FO fo;
min_element(v.begin(),v.end(),fo);
Only after some time I realised that min_element takes only a copy of
the variable fo. [I found that the size of the set is always zero
after the call to min_element]. As a solution to this problem, I
tried to define the variable s as a pointer to set (set<int> *s) and
then modified the code accordingly but when the code is running, half
way thru, the code aborts saying corrupted double-linked list:
0x000000000102beb0 ***.
What is the solution to this issue?
Thanks
suresh
In my code, the operator() method of a function object is designed to
fill a set which is a private data member of the function object. This
function object is used in min_element algorithm.
Since the min_element algorithm uses a copy of the function object (as
per my understanding - hoping it to be true), I am unable to access
the set data member of the function object. A minimal code is show
below:
class FO{
public:
bool operator()(int a, int b);
private:
set<int> s;
};
bool FO:
s.insert(a);
return (a<b);
}
vector<int> v;
//vector populated
FO fo;
min_element(v.begin(),v.end(),fo);
Only after some time I realised that min_element takes only a copy of
the variable fo. [I found that the size of the set is always zero
after the call to min_element]. As a solution to this problem, I
tried to define the variable s as a pointer to set (set<int> *s) and
then modified the code accordingly but when the code is running, half
way thru, the code aborts saying corrupted double-linked list:
0x000000000102beb0 ***.
What is the solution to this issue?
Thanks
suresh