Topic: Use remove_if in multimap
Author: Pongchi Chu <pchu@scdt.intel.com>
Date: 1998/04/29 Raw View
I am using remove_if for multimap. But compiler
(Microsoft VC++ 5) gives me following error message:
std::pair<class foo * const,class foo1 *>' :
'operator =' function is unavailable
I think there is no operator= defined for pair or there is a problem in
my code?
If remove_if does not work for multimap how can I sequnetially check
objects in
map and delete them conditionally?
Thanks
Pong
pchu@scdt.intel.com
///////////////////////////////////////////////////////////////
#include <map>
#include <algorithm>
using namespace std ;
class foo;
class foo1;
typedef multimap < foo*, foo1*, less <foo*> > myMap;
typedef pair <foo* const , foo1*> myPair;
class foo{
public:
foo():x(1){};
~foo(){};
const foo& operator=(const foo&) { return *this;}
int x;
};
class foo1{
public:
foo1():x(1){}
const foo1& operator=(const foo1&) { return *this;}
~foo1(){}
int x;
};
struct checker {
checker(){}
const bool operator() ( myPair pr) { return true; }
};
main()
{
myMap mp;
foo1 *f1= new foo1();
foo *f= new foo();
mp.insert( myPair (f, f1)); // insert ok
remove_if(mp.begin(), mp.end(), checker());// compile error
// test pair
myPair p(f,f1), p1(f,f1);
// p1=p; // can also cause compile error
return 1;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]