私の問題は、realloc() を呼び出すときの行にありますが、最初の "Elemento" #include #include using namespace std; で動作します。
typedef struct{
string palabra;
string* significados;
size_t tam;
} Elemento;
typedef struct{
Elemento* elementos;
size_t tam;
} Diccionario;
Diccionario crearDic(){
Diccionario dic;
dic.tam = 0;
return dic;
}
void agregarPalabraDic(Diccionario &dic, string pal, string sig){
dic.elementos = (Elemento*)realloc(dic.elementos,(dic.tam+1)*sizeof(Elemento));
dic.tam++;
dic.elementos[dic.tam-1].palabra = pal;
dic.elementos[dic.tam-1].significados = (string*)malloc(sizeof(string));
dic.elementos[dic.tam-1].tam = 1;
dic.elementos[dic.tam-1].significados[0] = sig;
}
そして、ここに main() があります:
int main(){
Diccionario dic = crearDic();
agregarPalabraDic(dic,"apple","red"); //no problem here
agregarPalabraDic(dic,"banana","yellow"); //thats the problem
...
}
私は何日も試していますが、何もありません。助けが必要です.. ty