2010-12-14 56 views
1

我使用boost :: multi_index视觉sutdio 2010年,这似乎与升压:: const_mem_fun和虚拟类方法使用时崩溃:visual C++ 2010内部错误boost :: multi_index?

class Node 
{ 
public: 
    virtual const std::string& getValue() const {return m_strValue;} 

protected: 
    std::string m_strValue; 

private: 
    struct byValue{}; 
    typedef boost::multi_index_container< 
    boost::shared_ptr<Node>, 
    boost::multi_index::indexed_by< 
     boost::multi_index::random_access<>, 
     boost::multi_index::ordered_non_unique< 
     boost::multi_index::tag<byValue>, 
     boost::multi_index::const_mem_fun<Node, const std::string& , &Node::getValue> 
     > 
    > 
    > NodeList; 
}; 

编译这个时候,视觉碰撞用这种消息的:

fatal error C1001: An internal error has occurred in the compiler. 
1> (compiler file 'msc1.cpp', line 1420) 
1> To work around this problem, try simplifying or changing the program near the locations listed above. 
1> Please choose the Technical Support command on the Visual C++ 
1> Help menu, or open the Technical Support help file for more information 

但是如果Node :: getValue不是虚拟的,编译就没问题。 有没有办法解决这个问题?

回答

1

您可以解决这个编译器错误使用user-defined key extractor

class Node 
{ 
public: 
    virtual const std::string& getValue() const {return m_strValue;} 

protected: 
    std::string m_strValue; 

private: 
    struct KeyExtractor 
    { 
     typedef std::string result_type; 

     const result_type& operator()(const boost::shared_ptr<Node>& p) const 
     { 
      return p->getValue(); 
     }   
    }; 

    struct byValue{}; 

    typedef boost::multi_index_container< 
    boost::shared_ptr<Node>, 
    boost::multi_index::indexed_by< 
     boost::multi_index::random_access<>, 
     boost::multi_index::ordered_non_unique< 
     boost::multi_index::tag<byValue>, 
     KeyExtractor 
     > 
    > 
    > NodeList; 
}; 
0

将错误报告给Microsoft。

不管代码有多怪,编译器都不应该崩溃。