我有一个类polymer
有static int count
。 当我创建一个新的polymer
添加到指针数组我正在使用count
找到阵列中的正确位置,然后我更新构造函数中的count
。在Windows中编译时,它工作。但是,在Linux(Ubuntu)中编译时,它会崩溃,除非我从构造函数中删除count
的更新。在函数调用更新的静态成员会导致崩溃
工作在Windows和Ubuntu的:
polymerPointer[polymer::count] = new polymer();
polymer::count++;
当构造不更新静态变量(见下文)
polymer::polymer(){
//sets up lots of variables but doesn't update the static member
};
崩溃在Ubuntu(工作在Windows中):
polymerPointer[polymer::count] = new polymer();
当构造函数更新静态变量时(参见下文)
polymer::polymer(){
//sets up lots of variables and then updates the static member
count++;
};
我可以重写代码,但我喜欢不必记得单独更新变量,这就是为什么我将更新放在构造函数中的原因。有什么想法出错?
什么调试说呢?在哪里开始回溯? – pmr 2012-01-16 20:06:38
显示更多代码,尤其是如何定义该变量,或许您忘记将其初始化为0?在调试器中运行该程序,并检查崩溃时发生的情况。 – unwind 2012-01-16 20:07:56