Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-12-05 20:09:05


Paul A. Bristow wrote:

>5 There are a handful of warning that an assignment operator could not be
>generated. The MS advice on this is:

>"To avoid this warning, specify a user-defined assignment operator for the
>class.

>[omitted for brevity]

>You can resolve the C4512 warning for this code in one of three ways:

>Explicitly define an assignment operator for the class.
>Remove const from the data item in the class.
>Use the #pragma warning statement. "

>I chose the latter easy option.

># pragma warning(disable: 4512) // assignment operator could not be
>generated

>Gurus views on this?

I am not a Guru, but I have had experience in this area. I have found that
the following will, more often than not, solve the problem:

   class base: public boost::noncopyable
   {
      // ...
   };

>Is there a Boost 'Standard' way to do document unhelpful warnings like
>this?

How about something along the lines of:

#include <boost/warn/push.hpp> // disable common warnings

// code generating warnings goes here

#include <boost/warn/pop.hpp> // revert to previous warning configuration

The compiler detection can then be placed in those files, without header
guards to allow them to be reused, e.g.:

// push.hpp

#if _MSC_VER
# pragma warning( push )
# pragma warning( disable : 4290 ) // C++ exception specification ignored
except to indicate a function is not __declspec(nothrow)
# pragma warning( disable : 4512 ) // assignment operator could not be
generated
   // ...
#else
   // other compilers
#endif

// pop.hpp

#if _MSC_VER
# pragma warning( pop )
#else
   // ...
#endif

Regards,
Reece

_________________________________________________________________
Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk