未初始化的局部变量
uninitialized local variable
我第一次尝试在visualstudio上编译c++,但遇到了一个错误。
/***Setup****/
struct id_priority{
int id;
int priority;
};
struct temp_heap{
int id;
int priority;
};
/**heapify up**/
void heapify(id_priority heap[], int index, int length, temp_heap temp){
}
int main(){
int *command_processed;
command_processed = new int[6];
id_priority *heap;
heap = new id_priority[1000];
temp_heap temp;
int index = 0;
int length = 0;
heapify(heap, index, length, temp);
return (0);
}
heapify(堆,索引,长度,临时);这一行说使用了未初始化的局部变量"temp",但这段代码在Linux上的终端上运行良好。我不知道这里出了什么问题。
我们不知道应该将temp初始化为什么。但这里有两种方法可以初始化它。我假设您希望它的字段都为0。
temp_heap temp = {0, 0};
和
temp_heap temp;
temp.id = 0; temp.priority=0;
相关文章:
- 为什么C++有不同的变量初始化方式?
- 静态 constexpr 成员变量初始化
- C++不同的变量初始化
- 全局和局部变量初始化与 constexpr 的差异背后的基本原理
- 是变量初始化失败吗?
- 视觉C++:在 DLL 加载期间,全局变量初始化顺序是否具有确定性?
- 类静态变量初始化顺序
- 使用 constinit 变量初始化 constexpr 变量
- 是否可以在不修改父类的情况下将成员变量初始化推迟到继承的类?
- 如何将局部变量初始化为C++的未知值
- 使用全局变量初始化不同编译单元中的其他全局变量
- 使用默认构造函数引用成员变量初始化错误
- 宏的 if 语句中的变量初始化
- 不稳定的C :每行适应性变化多变量初始化
- DLL 中的 C++ 静态局部变量初始化会导致_CrtIsValidHeapPointer异常
- C++-局部未初始化变量的值
- 在VS2015中c++局部静态变量初始化线程安全吗?
- 多线程环境中的静态局部变量初始化
- 局部静态变量初始化是线程安全的
- C++11 中线程安全局部静态变量初始化的成本