C++ 如何解决错误:无法将‘const std::__cxx11::basic_string<char>’转换为‘const key_type&’ {aka ‘const char&’}

时间:2021-04-14 08:26:07

标签: c++

<块引用>

我收到函数 bool TTrie<DataType>::hasChild(const DataType&) const 的错误:

无法将 ‘const std::__cxx11::basic_string’ 转换为 ‘const key_type&’ {aka ‘const char&’}

是不是因为.count()只接受char,而不是const DataType&

template< typename DataType>
class TTrie {
public:
  TTrie() {
    root = new TTrie();
  }


 /**                                                                                                         
   * Check whether a child linked by a specific value exists.                                                 
   * \param value a value                                                                                     
   * \return true if there is a link to a child labeled with the value,                                       
   *         false otherwise                                                                                  
   */
  bool TTrie<DataType>::hasChild(const DataType &value) const {
    std::map<char, TTrie<DataType>*> child = this->children;
    if(child.count(value)) {
      return true;
    }else{
      return false;
    }
  }

private:
  std::map<char, TTrie*> children;
  TTrie* root;
};





0 个答案:

没有答案