C++ 更改成员定义的顺序会损坏内存
我有一个班,有一些会员班。在我改变定义成员的顺序之前,一切都很正常 这是有效的代码:C++ 更改成员定义的顺序会损坏内存,c++,visual-studio-2012,C++,Visual Studio 2012,我有一个班,有一些会员班。在我改变定义成员的顺序之前,一切都很正常 这是有效的代码: class Core{ public: /// Initialization and main loop. bool initCore(int argc, char *argv[], string dirPath); int mainLoop(); /// Network impulse message static void networkImpulseCall
class Core{
public:
/// Initialization and main loop.
bool initCore(int argc, char *argv[], string dirPath);
int mainLoop();
/// Network impulse message
static void networkImpulseCallback(unsigned char* data, int length);
private:
bool _running;
string _directoryPath;
string _serverIP;
string _loginName;
string _pass;
string _myShowName;
/// System components.
ConfigurationFile _config;
ResourceParser _resourceParser;
Graphics _graphics;
Input _input;
ScriptInterpreter _scriptInt;
GUISystem _guiSystem;
EntityManager _entityManager;
/// Component threads.
thread *_netLoop;
thread *_graphLoop;
thread *_scriptLoop;
thread *_animationLoop;
thread *_physicsLoop;
/*
* Initializes the rest of the system after the login.
*/
bool _initPostLogin();
}
例如,如果我现在将图形
对象放在输入
对象下,我将获得访问冲突。违规发生的位置取决于我移动的对象。我试图通过移动对象来找出是哪个对象导致了错误,但不幸的是没有结果。发生冲突的对象的成员都未初始化(例如向量或互斥体)。
现在,我猜是某个地方的内存被破坏了。如果是的话,找到bug的最佳方法是什么?如果不是,问题出在哪里 输入类中是否有缓冲区?我猜你写过了结尾并损坏了下一个成员(图形)。你为指针分配了内存吗
库是否在访问对象之前解除对象分配?您可能会覆盖类的某些实例中的数据,可能是
\u input
成员。在外部编写,那么,您拥有的任何东西(结构、数组等)都将导致,这有一个不幸的特性,它有时似乎可以工作,但下一分钟它将使您的程序崩溃。您没有“成员类”。你有数据成员。你的编译器警告说什么(当然,你已经设置为最高级别)?你定义了任何构造函数吗?你试过调试AV发生的地方吗?