结构值不停留,值更改为-858993460 [英] Stucture values not staying, values changed to -858993460

查看:242
本文介绍了结构值不停留,值更改为-858993460的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显然在做错事或忘记某事。我已经定义了一个结构在头文件中有四个变量。然后,我在一个不同的.cpp函数中的那些变量赋值,然后尝试从结构中获取新值,并赋给另一个函数中的不同变量。问题是,我能够为结构中的变量赋值,但是当我尝试将这些值传递给其他变量时,它们变得像-858993460(这是根据调试器和观察线程)。
如何解决这个问题?

I'm clearly doing something wrong or forgetting something. I have defined a structure in a header file with four variables. I then assign values to those variables in a function located in a different .cpp then I try and take the new values from the structure and assign to different variable in another function. Problem is, I'm able to assign values to the variables in the structure but when I try and transfer those values to other variables they become something like -858993460(this is according to the debugger and watching the threads). How do I fix this?

结构用它的函数定义(即使不是目前不使用) >

Structure Defined with it's function(even though not it's not currently be used)

struct Setting {
    int Max;
    int Min;
    int Sample;
    int Points;
} Set1, Set2;

**将值分配给结构变量**

** Assigning Values to Structure variables**

void Settings::OnBnClickSet() {
    GetDlgItemText(ID_Points,str4);
    CW2A buf3((LPCWSTR)str4);
    Serial Value;
    Value.Set1.Points = atoi(buf3);
}

尝试将这些值传输到另一个变量 / p>

Attempting to transfer those values to another variable

bool Serial::Temperature(CString) {
    int Max,Min,SampleTime,Points;
    Max = Set1.Max;
    Min = Set1.Min;
    SampleTime = Set1.Sample;
    Points = Set1.Points;
}


推荐答案


但是当我尝试并将这些值传递到其他变量时,它们变成了像-858993460

but when I try and transfer those values to other variables they become something like -858993460

这是一个魔术数字。转换为十六进制,得到0xcccccccc。

That's a Magic Number. Convert it to Hex to get 0xcccccccc. Which is the value that's used to initialize variables when you build your program with the Debug configuration settings.

因此,无论何时在调试器中看到它,你都会啊!我正在使用一个未初始化的变量!我们可以从代码片段中真正看到的是,你的Set1结构从来没有初始化。专注于应该这样做的代码,非零的赔率,你只是忘了编写代码或使用错误的结构对象。

So whenever you see it back in the debugger, you go "Ah! I'm using an uninitialized variable!" All we can really see from the snippet is that your Set1 struct never got initialized. Focus on the code that's supposed to do this, with non-zero odds that you just forgot to write that code or are using the wrong structure object.

这篇关于结构值不停留,值更改为-858993460的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆