Boost logo

Boost Users :

Subject: [Boost-users] [ptr_container][ptr_map]
From: Aaron Levy (aaron.levy_at_[hidden])
Date: 2014-09-13 16:52:43


Consider the following code:

class Base
{
public:
   virtual ~Base() = 0 {};
   virtual double get() = 0;
};

class D1 : public Base
{
public:
  D1(double n) : val_(n) {}
  double get() const { return val_; }

private:
  double val_;
};

class D2 : public Base
{
  D2(double n) : val_(n) {}
  double get() const { return val_; }

private:
  double val_;
};

bool operator < (const Base& left, const Base& right)
{
  return (left.get() < right.get());
}

I can create a ptr_set of Base like this:

boost::ptr_set<Base> set;

But I can't create a ptr_map with Base as key, like this:

boost::ptr_map<Base, Base> map;

The problem is that Base is abstract and so the key cannot be instantiated by ptr_map. What is the cause for this distinction between ptr_set and ptr_map.

--
Aaron Levy
aaron.levy_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net