我创建了一个混合方法,该方法通过引用获取两个列表。比创建列表1和2分配元素的混合列表(3)比返回列表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;
}

最佳答案

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

关于c++ - 堆上没有匹配功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47311757/

10-13 07:46