Boost logo

Boost :

Subject: [boost] [move] "using Base::operator=;"
From: Jeffrey Hellrung (jhellrung_at_[hidden])
Date: 2009-09-07 23:57:28

Hey Ion, it's me again,

I have roughly the following situation:

#include <iostream>
#include <boost-sandbox/move/boost/move/move.hpp>

struct B
     B& operator=(const B&) // Auto-generated one is also sufficient...
         std::cout << "B::operator=(const B&)" << std::endl;
         return *this;
     // Possibly other overloads of operator=...

class D : public B
     D() { }
     D(const D&) { }
     D(BOOST_RV_REF( D )) { }
     using B::operator=;
     D& operator=(BOOST_COPY_ASSIGN_REF( D ))
         std::cout << "D::operator=(const D&)" << std::endl;
         return *this;
     D& operator=(BOOST_RV_REF( D ))
         std::cout << "D::operator=(D&&)" << std::endl;
         return *this;

Now, unfortunately,

const D source;
D dest;
dest = source;

invokes B::operator=(const B&) rather than
D::operator=(BOOST_COPY_ASSIGN( D )), even if it's just the
auto-generated one!

I've been thinking about the best way to deal with this. In my
situations (plural since this has now bit me twice before I figured out
the cause), I do want the operator= overloads provided by the base class
to be available along with the operator= overloads in the derived class,
and this works fine if the derived class has an overload of operator=
that accepts a const D& rather than const rv<D>&.

Do you (or anyone else) have any suggestions as to the best (cleanest,
easiest to maintain, etc.) way to proceed?

Also, I think this might be another "gotcha" to add to the documentation.


- Jeff

Boost list run by bdawes at, gregod at, cpdaniel at, john at