I have the following:
class X : public boost::noncopyable
{...};
class Y
{
public:
const boost::ptr_vector<X>& getXs() const;
private:
boost::ptr_vector<X> m_xs;
}
int main()
{
Y y1;
//...
const boost::ptr_vector<X>& mx = y1.getXx();
BOOST_FOREACH(boost::ptr_vector<X>::value_type x, mx)
{
// do something with x!
}
}
It compiles but it doesn't link! It says that implicit default copy constructor for X
is needed by the BOOST_FOREACH.
How can I iterate over the pointers to X only... no copy contructor, using BOOST_FOREACH
.
Thanks.
Try using references in
BOOST_FOREACH()
, .i.e.