我有这个结构:
struct event_ {
bool is_crossover = false;
bool is_birth = false;
bool is_repetitive = false;
int eID = 0;
bool inicio_fin = false;
fecha inicio_fecha;
fecha fin_fecha;
locacion inicio_l;
string eLatitud_i = 0;
string eLongitud_i = 0;
locacion fin_l;
string eLatitud_f = 0;
string eLongitud_f = 0;
personaje_info personajes_evento; //This is a class
int cantidad_personajes = 0;
string nombre;
string descripcion;
string tipo_evento;
event_ *sig, *ant;
};
然后,当我调用函数时:
event_ *n = new event_;
它向我发送了一个访问冲突错误:
Exception thrown at 0x0F69F6E0 (ucrtbased.dll) in Auxiliar Libros.exe: 0xC0000005: Access violation reading location 0x00000000.
有人知道为什么会这样吗? 作为附加信息,我运行了代码指标分析,在此之前,该程序运行良好。它还告诉我有关异常的信息,我应该怎么做?
最佳答案
这段代码
string eLongitud_f = 0;
使用 NULL 指针调用字符串构造函数(0
是 NULL 指针的另一种写法),导致您的访问验证错误。
您认为这段代码在做什么?显然 0
是一个整数而不是 string
。你是这个意思吗?
string eLongitud_f = "0";
或者你是这个意思?
string eLongitud_f = "";
也许你甚至是这个意思
double eLongitud_f = 0.0;
你也可以只拥有这个
string eLongitud_f;
这与上面的第二个选择相同。所有这些都是可能的,很难知道你真正想要的是哪个,但根本问题是你有一个字符串变量并且你试图给它一个不是字符串的值。
关于c++ - 访问冲突新的 C++ 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55074543/