[英]cv::SimpleBlobDetector detect() produce access violation exception in Visual Studio 2010
[英]Access Violation on Visual Studio 2010
我的C ++代碼有問題,看看這個函數:
void insere(titem x){
tlista *aux;
aux = (tlista*)malloc(sizeof(tlista));
aux->item = x;
ultimo->prox = aux;
ultimo = ultimo->prox;
aux->prox = NULL;
}
當行: aux->item = x;
是的,Visual Studio說:
TP6.exe中0x53eacafa(msvcr100d.dll)的未處理異常:
看看我的struct titem:
struct titem {
int prioridade;
string nome;
int freq;
};
在Dev-C ++中,代碼工作正常! 可能出現什么問題,如何解決?
您正在使用malloc
為對象分配內存。 這將分配內存,但不會初始化對象。 對於非POD成員來說這是一個問題,例如aux->item.nome
。
而不是使用malloc,你需要使用new
。
tlista *aux = new tlista;
完成結構后,使用delete
來處理它。
delete aux;
由於您使用的是C ++,因此您應該忘記所有關於malloc
和free
。 使用C ++中的new
和delete
執行堆分配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.