为什么这段代码错了?我缺少有关的行为的东西delete和delete[]?
void remove_stopwords(char** strings, int* length)
{
char** strings_new = new char*[*length];
int length_new = 0;
for(int i=0; i<*length; i++) {
if(is_common_keyword(strings[i]) == 0) {
strings_new[length_new] = strings[i];
length_new++;
}
else {
delete strings[i];
strings[i] = nullptr;
}
}
delete[] strings;
strings = new char*[length_new];
for(int i=0; i<length_new; i++) {
strings[i] = strings_new[i];
}
delete[] strings_new;
*length = length_new;
}
Run Code Online (Sandbox Code Playgroud)
解释:这段代码应该采用一系列C风格的字符串并删除它们的一些特定字符串; 使用new []创建C样式字符串数组,并使用new创建每个C样式字符串.代码的结果是没有单词被取消,但数组只是被切片.
是否应该将动量添加到网络中每个节点的偏差项中,或者最好仅添加权重?