堆上没有匹配的功能

时间:2017-11-15 15:50:44

标签: c++

我创建了一个混合方法,它通过引用获取两个列表。我已经创建了混合列表(3),我从列表1和2中分配元素,而不是返回列表3.

当我尝试实现它时,它在堆栈中工作,但不是堆。 什么可能是一个问题?

(sth3 = sth3-> mix(sth1,sth2);) - 我没有匹配的功能问题。

不工作:

    Sequence<int,string> *sth1 = new Sequence<int,string>();
    sth1->AddNode(1,"n1");
    sth1->AddNode(2,"n2");

    Sequence<int,string> *sth2 = new Sequence<int,string>();
    sth2->AddNode(10,"n1");   

    Sequence<int,string> *sth3 = new Sequence<int,string>();
    sth3 = sth3->mix(sth1,sth2);
    sth3->Print();

工作一:

    Sequence<int,string> st1;
    st1.AddNode(1,"n1");

    Sequence<int,string> st2;
    st2.AddNode(10,"n1");

    Sequence<int,string> st3;
    st3 = st3.mix(st1,st2);
    st3.Print();

简化功能组合(..)

template<typename key,typename info>
Sequence<key, info> Sequence<key, info>::mix(const Sequence<key, info> &s1, const Sequence<key,info> &s2)
{
            Sequence<key,info> s;
            Node<key, info> *curr1 = s1.head;
            Node<key, info> *curr2 = s2.head;

            while (s.count < 10)
            {
                s.AddNode(curr1->GetId(), curr1->GetData())
                curr1 = curr1->GetNext();
                s.AddNode(curr2->GetId(), curr2->GetData())
                curr2 = curr2->GetNext();

                if (curr1 == NULL && curr2 == NULL)
                    break;

            }

    return s;
}

2 个答案:

答案 0 :(得分:2)

sth3 = sth3->mix(sth1,sth2)更改为*sth3 = sth3->mix(*sth1,*sth2)

答案 1 :(得分:0)

在堆中,你给出了一个指向期望引用的函数的指针,你必须对它们进行反驳。