我正在编写以下代码,但出现了 Stack around variable is corrupted
错误。我检查过类似的帖子,但无法解决问题。我对 C++ 也很陌生。这是我的代码。
///CLASS DEFINITION
class Trellis{
private:
int m;
int Nstates;
int StateTransition[];
public:
Trellis();
Trellis(int M);
};
这里是方法的定义
Trellis::Trellis(int M){
m = M;
Nstates = pow(2, M - 1);
for (int i = 0; i < Nstates; i++){
StateTransition[i] = i;
}
}
主要内容() {
Trellis Tu = Trellis(3);
返回0;
我得到的错误是运行时检查失败 #2-Stack around variuble 'Tu' was corrupted;
最佳答案
你没有为 StateTransition
分配任何内存,你想要这样的东西:
StateTransition = new int[Nstates];
在 ctor 中的 for
循环之前。
关于c++ - Stack around variable is corrupted 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24759937/