int main()
{
    ...
    ...
    return 0;
}
如上所示
XP下运行之后说该程序遇到问题需要关闭
然后我在VC6中按F10开始调试
一路无事
在return 0;之后继续F10
进入汇编代码……汗!
狂按数十次之后
说发生访问冲突

return 0之后的事情还要我来管?
何解?

解决方案 »

  1.   

    如果不想贴代码,建议一个最笨也最有效的方法:
    1.注释main函数中除return 0;的代码,如果运行仍出问题,那么遵循一楼的解答,退出;
    2.部分注释main函数中除return 0;的代码,如果运行仍出问题,重复执行2,如果运行不出问题,检查注释掉的代码,退出。
      

  2.   

    Yes. It's a problem you need to solve.main is not the true entry point of your program. There are other code executed before and after that.The before code is normally for C/C++ runtime library initialization and global variable initialization. The after code is for global variable deinitialization.For example, if you have a class Class1 and a global variable Class1 Global1, Global1's constructor will be called before main and destructor called after main.There are two possible reasons your problem could happen.1) You have a stack corruption.
    2) You have a heap corruption.If you program is simple, read the code carefully may find the problem. Otherwise, use some times like gflags and page heap (search for them).Feng Yuan [MSFT] (www.fengyuan.com, blog.joycode.com/fyuan)
      

  3.   

    我想是正是因为内存释放或者对象析构的问题
    是个小程序
    我因为图方便使用了不少的全局对象
    看来现在麻烦了
    我得改一改我的程序
    记得Lippman在他的《Essential C++》(侯捷译)中说到
    “事实上,C++编程最难的部分之一,便是了解何时需要定义destructor而何时不需要。”(P108)
    看来我是遇上了“最难的部分”
    HOHO
    感谢各位
    尤其是竟然还有E文说话的牛人(似乎是M$的人)
    结贴!