函数访问冲突读取位置
function access violation reading location
我有一个函数,当 return 语句在 else 内时,它只返回访问冲突读取位置错误,但当它在 else 之外时,没有错误被打开,但我有时会得到相同的返回值,当由于我不应该的代码。这是代码:
void askUser(){
std::cout << "Level: ";
std::cin >> level;
for (int x = 0; x < 3; x++){
word = getWord(level);
std::cout << word << std::endl;
}
}
std::string getWord(int level){
int randomNumber = rand() % 3;
if (usedWords[0].find(line[level - 1][randomNumber]) != usedWords[0].end()){
getWord(level);
}
else{
usedWords[0].insert(line[level - 1][randomNumber]);
return line[level - 1][randomNumber]; //returns the access violation error
}
//if the return was here no access violation but can return previous return values which shouldn't happen
}
我不太确定究竟是什么导致了错误,但我认为这与 return 语句有关。
问题是当 if
语句中的条件为真时,您不会返回任何内容。 该函数说你应该返回一个字符串,但你只是到了函数的末尾。 未定义的行为。
相关文章:
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- (此函数用于计算 SMA).在 FA.exe 中0x00509159引发异常: 0xC0000005:访问冲突读取位置0
- 0xC0000005:读取位置0xCDCDCDC1时发生访问冲突
- 0xC0000005:读取位置0xCDCDCDCD时发生访问冲突
- 读取类的析构函数中的位置时发生访问冲突
- 0x0F50DF58:0xC0000005:访问冲突读取位置0x0047CA04时未处理的异常
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 0xC0000005:访问冲突读取位置0x0000000000000008
- C++访问冲突读取位置0xDDDDDDCD当我尝试删除已更新的数组时
- 使用向量的函数崩溃,调试器说访问冲突读取位置
- 如何在c++中从txt文件的随机位置读取数据
- 从C 中的特定位置读取文本文件的一行
- 如何从字符 * 缓冲区中的位置 y 读取 x 个字符
- 从文件C++中的特定位置读取
- Xcode 4输出文件并从奇怪的位置读取
- 如何从最后一个光标位置读取文件
- 如何从字符串流中的同一位置读取两次
- 从搅拌机的特定内存位置读取数据(结构)
- <向量>线程安全在不同位置读取/写入吗?
- 从位置读取文件(到位置)