/* This is gcc's output with all #defines (below) defined, showing the error caused by using an object of type boost::initialized as lvalue. This can be fixed by implementing the method boost::initialized& boost::initialized::operator=(T const&) for the initialized class. File Line Message main.cpp In function 'int main(int, char**)': main.cpp 57 error: no match for 'operator=' in 'b = 39' boost/utility/value_init.hpp 120 note: candidates are: boost::initialized& boost::initialized::operator=(const boost::initialized&) [with T = int] */ #define INITIALIZED_FAILURE #define FOO_FAILURE #define FOO_ASSIGNMENT_OPERATOR_FROM_INT #include using std::cout; using std::endl; #include using boost::initialized; using boost::get; class foo { public: int x; foo() : x(38) {} operator int& () { return x; } operator int const& () const { return x; } #ifdef FOO_ASSIGNMENT_OPERATOR_FROM_INT foo& operator=(int const& o) { x = o; return *this; } #endif foo& operator=(foo const& o) { // if foo& foo::operator=(int const&) is undefined, this one is considered a "candidate" for the lvalue but not used x = o; return *this; } }; int main(int, char**) { foo f; cout << endl << f; #ifdef FOO_FAILURE f = 39; // succeeds if foo& foo::operator(int const&) defined, fails otherwise cout << endl << f; #endif f.operator int&() = 40; // succeeds cout << endl << f; cout << endl; initialized b; cout << endl << b; #ifdef INITIALIZED_FAILURE b = 39; // fails (with initialized& initialized::operator=(initialized const&) considered as above) cout << endl << b; #endif b.operator int&() = 40; // succeeds cout << endl << b; get(b) = 41; // succeeds cout << endl << b; cout << endl; return 0; }