gpt4 book ai didi

c++ - 没有来自 'const std::__1::basic_string to ' std::__1::basic_string *' 的可行转换

转载 作者:搜寻专家 更新时间:2023-10-31 01:35:30 25 4
gpt4 key购买 nike

我目前正在为一个类项目工作,其中我必须在 C++ 中实现布谷鸟哈希。问题是,C++ 和我从来都不是 friend ,而且我认为我们永远不会...

具体的问题是,我无法在已经存在的对象上设置指针。当我这样做时,我得到了编译错误:

没有从 'const std::__1::basic_string 到 'std::__1::basic_string' 的可行转换*

两条语句都出现错误:

E * activeE = e;
E * tempE = v1[pos];

v1 是一个 E 对象数组。

我认为这个错误是由于我对C++基本概念的普遍误解造成的。我认为对你们来说这个问题是个笑话,但无论如何我希望你们能帮助我。

template <typename E, size_t N>
void Hashing<E,N>::add_(const E& e) {

size_t pos = h1(e);
size_t i = 0;

E * activeE = e;
E * tempE = v1[pos];

while (i < nmax) {
if (tempE == NULL) {
v1[pos] = activeE;
break;
}

v1[pos] = activeE;
activeE = tempE;

pos = h2(activeE);
tempE = v2[pos];

if (tempE == NULL) {
v2[pos] = activeE;
break;
}

v2[pos] = activeE;
activeE = tempE;

pos = h1(activeE);
tempE = v1[pos];
}

}

最佳答案

你有 const E& eHashing<E,N>::add_方法,但在其中分配 e指向 E 的指针- 实际上这会产生不同的错误:

 'const std::__1::basic_string to 'std::__1::basic_string*"
^

所以修复,因为这是改变:

 E * activeE = e;
E * tempE = v1[pos];

 const E * activeE = &e;
const E * tempE = &v1[pos];

关于c++ - 没有来自 'const std::__1::basic_string<char> to ' std::__1::basic_string<char> *' 的可行转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271245/

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