1

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.

4

1 回答 1

0

来自MSDN 文档

您可以通过以下三种方式之一解决代码的 C4512 警告:

  • 为类显式定义赋值运算符。
  • 从类中的数据项中删除 const 或引用运算符。
  • 使用#pragma警告语句来抑制警告。

如果继承自boost::noncopyable(这将是第一个选项)不起作用,并且您无法访问类源(第二个选项),那么您将收到#pragma警告

#pragma warning( disable : 4152 )
// your offending code
#pragma warning( pop ) 
于 2013-09-20T18:00:27.910 回答