如何搜索BST模板并返回地图

时间:2019-05-28 11:50:17

标签: c++ templates search return binary-search-tree

所以我想从BST内的节点返回一个映射,如果它与目标值(带有年份的映射)相同,然后将该映射返回给一个类。

我试图做函数指针,但我不明白为什么我可以让它们在main.cpp中工作,但不能在类中工作。至于这个返回值,香港专业教育学院以前尝试过,目前正在收到此错误

   Error    C2672   'operator __surrogate_func': no matching overloaded function found  Simple Read Date    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility    3084     

   Error    C2893   Failed to specialize function template 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&) const'   Simple Read Date    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility    3084    

Main.cpp

    DataCollection dc;
    typedef map<int, map<int, vector<WeatherLog>>> typeMap;
dc.client_call(dataMap,tree);

TBST.h

    template <class T>
    T& TBST<T>::Search(T target)
    {
        return SearchPrivate(root, target);
    }
    template <class T>
   T& TBST<T>::SearchPrivate(Node* ptr, T target)
    {
        if (root != nullptr && ptr != nullptr)
        {
            if (ptr->key > target)
                SearchPrivate(ptr->left, target);
            else if (ptr->key < target)
                SearchPrivate(ptr->right, target);
            else if (ptr->key == target)
                return ptr->key;
         }
         else
        {
            std::cout << "No target data found\n";
        }
    }

DataCollection.cpp

typedef map<int, map<int, vector<WeatherLog>>> typeMap;
typedef map<int, vector<WeatherLog>> innerMap;
//This is what im trying to get to work        
typeMap oneYear;
            typeMap returnOneYear;
            innerMap empty;
            oneYear[year] = empty;
            returnOneYear = tree.Search(oneYear);

WeatherLog.h

struct WeatherLog {
    Date d;
    Time t;
    float speed;
    float sRads;
    double airTemp;
};

所以我只希望搜索能够返回返回returnOneYear的地图

0 个答案:

没有答案