gpt4 book ai didi

c++ - 堆上没有匹配函数

转载 作者:行者123 更新时间:2023-11-28 01:40:34 24 4
gpt4 key购买 nike

我创建了一个 mix 方法,它通过引用获取两个列表。我创建了混合列表 (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();

简化函数 mix(..)

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com