Question

I am trying to create a template class with a boost.bimap as a member. However, when following the usual typedef protocols, my compiler (I'm using Visual Studio Express 2012) produces a whole ream of C4512 (assignment operator could not be generated) warnings. Strangely enough, the code will compile, and if I fully implement the class, things work correctly. I'd prefer to know the cause of the warning though, and how to avoid it, if possible. If anyone had any ideas, I'd be very grateful!

#ifndef TESTCLASS_H
#define TESTCLASS_H

#include <map>
#include <boost/bimap.hpp>

template<typename T>
class TestClass
{
public:
    TestClass()
    {

    }
private:
    typedef boost::bimap<int,int> bimap_t;
    typedef bimap_t::value_type valuetype;
};

#endif // TESTCLASS_H

The bimap code, outside of a template, doesn't cause any warnings to appear.

Was it helpful?

Solution

From the MSDN documentation

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

  • Explicitly define an assignment operator for the class.
  • Remove const or the reference operator from the data item in the class.
  • Use the #pragma warning statement to suppress the warning.

If inheriting from boost::noncopyable (which would be the first option) does not work, and you cannot access the class source (second option) then you are left with the #pragma warning

#pragma warning( disable : 4152 )
// your offending code
#pragma warning( pop ) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top