错误C2893无法专门化功能模板'unknown-type std :: equal_to <void> :: operator()(_ Ty1 &&,_ Ty2 &&)noexcept(<expr>)const'

时间:2019-10-13 02:34:00

标签: c++

我使用模板来创建两个名为baglinked_list的类。我编写了一个名为find的函数作为bag类的成员。创建该功能是为了在包类中查找元素的位置。

我已经重载了operator==ThreeD类的linked_list。我声明了元素指针item<linked_list<ThreeD<double>>>* p,并且find函数正常运行。

但是,当涉及到另一个元素item<list<linked_list<ThreeD<int>>>>* p20时,程序崩溃就会出现错误2893。为什么会发生这种情况?

ThreeD类:

template <class T> class ThreeD {
public:
    T ht;
    T wid;
    T dep;
    ThreeD() { ht = wid = dep = 0; }
    ThreeD(T i) { ht = wid = dep = i; }
    ThreeD(T a, T b, T c) { ht = a; wid = b; dep = c; }
    T getVol() { return ht * wid * dep; }
    //two objects are equal if their getVol() return the same value.
    bool operator==(ThreeD<T>& t1) {
        if (getVol() == t1.getVol()) {
            return true;
        }
        else { return false; }
    }

    bool operator!=(ThreeD<T>& t1) {
        if (getVol() == t1.getVol()) {
            return false;
        }
        else { return true; }
    }
};

operator==用于linked_list类:

bool operator==(linked_list& L) {
        node<T>* it1 = head;
        node<T>* it2 = L.head;
        int count1 = 0;
        while (it1 != nullptr) {
            count1++;
            it1 = it1->next;
        }
        int count2 = 0;
        while (it2 != nullptr) {
            count2++;
            it2 = it2->next;
        }
        if (count1 != count2) { return false; }
        else {
            it1 = head;
            it2 = L.head;
            while (it1 != nullptr && it2 != nullptr) {
                if (it1->value != it2->value) { return false; }
                it1 = it1->next;
                it2 = it2->next;
            }
            return true;
        }
    }

main功能:

int main(){
item<linked_list<ThreeD<double>>>* p2;
    p2 = BLTD.find(LTD1);

item<list<linked_list<ThreeD<int>>>>* p20 = B16.find(V4);
    if (p20 != nullptr) cout << (p20->data).size() << endl;

}

0 个答案:

没有答案
相关问题