首先感谢原文作者分享自己的经验,本人认为这篇文章是很有价值的。
附原文地址:http://blog.sina.com.cn/s/blog_544734b40100dbx1.html
1, 尽量不用"Using namespace".
2, 变量不初始化,然后赋值给其他变量的时候,debug下会弹出assert框.
3, 机器太慢,需要更好的配置.
4, 一些定义在2008的系统文件里已经有了.
enum SHIL
{
};
SHIL_LARGE 已经在下面的文件里定义了
D:"Program Files"Microsoft SDKs"Windows"v6.0A"include"shellapi.h
#if (NTDDI_VERSION >= NTDDI_WINXP)
#define SHIL_LARGE
#define SHIL_SMALL
#define SHIL_EXTRALARGE
#define SHIL_SYSSMALL
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
#define SHIL_JUMBO
#define SHIL_LAST
#else
#define SHIL_LAST
#endif // (NTDDI_VERSION >= NTDDI_LONGHORN)
#endif // (NTDDI_VERSION >= NTDDI_WINXP)
typedef enum _SEARCH_RESTR
{
}SEARCH_RESTR;
解决办法:可以加一个namespace
5, warning C4996: '_itow': This function or variable may be unsafe. Consider using _itow_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
warning C4996: 'gmtime': This function or variable may be unsafe. Consider using gmtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
warning C4996: 'wcstok': This function or variable may be unsafe. Consider using wcstok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
用_s版本的字符串处理函数更安全.
6, wchar_t作为c++的内部类型,不能用unsigned short代替.可以通过下面的开关来设置Whether treat wchar_t as Build-in Type.
7,return NCStr ( c_str() + nFirst, end() ); --> return NCStr ( c_str() + nFirst, length() - nFirst );
迭代器被封装了,所以这时候对CRangeT ( pointer pHead = 0, pointer pTail = 0 )和CRangeT ( pointer pHead, int nLen ),产生歧义,不知道该用哪个构造函数
8,
#define TVI_ROOT
#define TVI_FIRST
#define TVI_LAST
#define TVI_SORT
这几个值是指针,不是整型
9, _L("SettingFailed")) ).
10, 取函数指针
11, 函数必须有返回值,定义变量必须指定类型
12, error C2471: cannot update program database 'e:"projects"connect"c5_hz_2008"obj"release"triext"vc90.pdb
打补丁VS90-KB946040.exe.
13,
…
MSHTML::IHTMLDocument3Ptr pDoc3 = NULL;
pDoc3 = pDoc; 这里2008不能通过编译,待研究.
14, time_t的定义,
localtime(&block_header.m_tDate);
vc6是32位的:
#ifndef _TIME_T_DEFINED
typedef long time_t;
#define _TIME_T_DEFINED
#endif
vc2008默认是64位:
#ifndef _TIME_T_DEFINED
#ifdef _USE_32BIT_TIME_T
typedef __time32_t time_t;
#else
typedef __time64_t time_t;
#endif
#define _TIME_T_DEFINED
#endif
15, class CAniFrame : CWindowImpl< CAniFrame >
vc6默认是public继承
vc2008默认是private继承
17, 1>."res"Installer.exe.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the path specified.
cause:Installer.exe.manifest不知道什么时候被加到resource里去了,删除即可。
18, typedef int (WINAPI* PTGetSSOTicketProc)(CSSOSink* pSink, HWND hParent, LPTSTR lpszSiteURL, BOOL bForce=FALSE, LPVOID lpData=NULL);
指向函数的指针不允许参数带默认值
19, For循环内部定义的变量作用域只在循环体内部.
20, STL里的iterator 不要直接传递给指针。或把指针传给iterator
//below example is illegal
//below example is right
21, 在你涉及到一个在 template(模板)中的 nested dependent type name(嵌套依赖类型名)的任何时候,你必须把单词 typename 放在紧挨着它的前面
CTLMap<KEY, ARG_KEY, VALUE, ARG_VALUE>::CAssoc*
CTLMap<KEY, ARG_KEY, VALUE, ARG_VALUE>::NewAssoc() -->typename CTLMap<KEY, ARG_KEY, VALUE, ARG_VALUE>::CAssoc*
CTLMap<KEY, ARG_KEY, VALUE, ARG_VALUE>::NewAssoc()
ex:
template<typename C> // this is valid C++
void print2nd(const C& container)
{
}
22, typedef 必须是public才能被外界访问到.
23, 在如下情况下必须明确指定模板参数
template< class TBase, class TWinTraits = CControlWinTraits >
class UI_EXPORT CTriSimplestWndImpl : public CWindowImpl<CTriSimplestWndImpl , TBase, TWinTraits>
{
public:
};
template< class TBase, class TWinTraits = CControlWinTraits >
class UI_EXPORT CTriSimplestWndImpl : public CWindowImpl<CTriSimplestWndImpl<TBase,TWinTraits>, TBase, TWinTraits>
{
public:
};
…
还有很多warning应该去关注,争取做到无warning