2010-12-14 3 views
1

J'utilise boost :: multi_index avec sutdio visuel 2010, et il semble se bloquer lorsqu'il est utilisé avec boost :: const_mem_fun et méthodes de classe virtuelle:erreur interne Visual C++ 2010 avec 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; 
}; 

lors de la compilation cela, accident visuel avec ce genre de message :

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 

mais si Node :: getValue n'est pas virtuel, la compilation est correcte. est-il un moyen de contourner ce problème?

Répondre

1

Vous pouvez contourner ce bug du compilateur en utilisant un 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

Signaler le bogue à Microsoft.

Peu importe à quel point le code est étrange, le compilateur ne devrait pas planter.

Questions connexes