1. lifescope of int i in for(int i; i< size; ++i)
in VC6, the codes below are ok
for(int i = 0; i< 10; ++i)
{
//...
}
for(i = 20; i< 40;++i)
{
//...
}
but in VS2005, we should write like below:
for(int i = 0; i< 10; ++i)
{
//...
}
for(int i = 20; i< 40;++i)
{
//...
}
in fact, from vs.net, the compiler accord with C++ standard more than VC6.
If you are porting a VC6 project to VS2005, you will encounter many many codes like this.
2. ON_WM_NCHITTEST (and other MFC macros) won't compile in VS2005
VS2005中,ON_WM_NCHITTEST宏编译不过
When I add a message handler of ON_WM_NCHITTEST to a CControlbar-derived class, it compiles error:
error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CMenuBar::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)' Cast from base to derived requires dynamic_cast or static_cast
To fix this bug, we should change the prototype of OnNcHitTest
from
afx_msg UINT OnNcHitTest(CPoint point);
to
afx_msg LRESULT OnNcHitTest(CPoint point);
本文探讨了从VC6迁移到VS2005时遇到的问题,包括变量作用域的变化、ON_WM_NCHITTEST宏的编译错误及解决方法、以及VS2005中建议避免使用的潜在危险函数。
1306

被折叠的 条评论
为什么被折叠?



