首先感谢原文作者分享自己的经验,本人认为这篇文章是很有价值的。

附原文地址:http://blog.sina.com.cn/s/blog_544734b40100dbx1.html

 

1, 尽量不用"Using namespace".

2, 变量不初始化,然后赋值给其他变量的时候,debug下会弹出assert.

3, 机器太慢,需要更好的配置.

4, 一些定义在2008的系统文件里已经有了.

enum SHIL

{

    SHIL_LARGE = 0,

    SHIL_SMALL = 1,

    SHIL_EXTRALARGE = 2,

    SHIL_SYSSMALL = 3,

    SHIL_USER64,

};

 

SHIL_LARGE 已经在下面的文件里定义了

D:"Program Files"Microsoft SDKs"Windows"v6.0A"include"shellapi.h

#if (NTDDI_VERSION >= NTDDI_WINXP)

#define SHIL_LARGE           // normally 32x32

#define SHIL_SMALL           // normally 16x16

#define SHIL_EXTRALARGE     2

#define SHIL_SYSSMALL         // like SHIL_SMALL, but tracks system small icon metric correctly

#if (NTDDI_VERSION >= NTDDI_LONGHORN)

#define SHIL_JUMBO           // normally 256x256

#define SHIL_LAST           SHIL_JUMBO

#else

#define SHIL_LAST           SHIL_SYSSMALL

#endif // (NTDDI_VERSION >= NTDDI_LONGHORN)

#endif // (NTDDI_VERSION >= NTDDI_WINXP)

 

typedef enum _SEARCH_RESTR

{

    SEARCH_ALL = 0,已经在下面的文件里定义了"D:"Program Files"Microsoft SDKs"Windows"v6.0A"include"winioctl.h"

    SEARCH_CHAT,

    SEARCH_FILE,

}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.

 Property --> C/C++ --> language --> Treat wchar_t as Build-in Type (NO).

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,    enum EInsertAfter

    {

        e_iaFirst           = TVI_FIRST,

        e_iaLast            = TVI_LAST,

        e_iaSort            = TVI_SORT,

    };

 -->

   enum EInsertAfter

    {

        e_iaFirst           = (int)TVI_FIRST,

        e_iaLast            = (int)TVI_LAST,

        e_iaSort            = (int)TVI_SORT,

    };

#define TVI_ROOT                ((HTREEITEM)(ULONG_PTR)-0x10000)

#define TVI_FIRST               ((HTREEITEM)(ULONG_PTR)-0x0FFFF)

#define TVI_LAST                ((HTREEITEM)(ULONG_PTR)-0x0FFFE)

#define TVI_SORT                ((HTREEITEM)(ULONG_PTR)-0x0FFFD)

这几个值是指针,不是整型

9, _L("SettingFailed")) ). _L宏没有定义

10, 取函数指针 CXmpp::IQRoomList --> &CXmpp::IQRoomList

11, 函数必须有返回值,定义变量必须指定类型

12, error C2471: cannot update program database 'e:"projects"connect"c5_hz_2008"obj"release"triext"vc90.pdb

打补丁VS90-KB946040.exe.

13,     CComQIPtr< IHTMLDocument2> pDoc;

MSHTML::IHTMLDocument3Ptr pDoc3 = NULL;

pDoc3 = pDoc; 这里2008不能通过编译,待研究.

   

14, time_t的定义,

localtime(&block_header.m_tDate);

vc632位的:

#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.

causeInstaller.exe.manifest不知道什么时候被加到resource里去了,删除即可。

18, typedef int (WINAPI* PTGetSSOTicketProc)(CSSOSink* pSink, HWND hParent, LPTSTR lpszSiteURL, BOOL bForce=FALSE, LPVOID lpData=NULL);

指向函数的指针不允许参数带默认值

19, For循环内部定义的变量作用域只在循环体内部.

         for(int i=0;i<100;++i){}; j = i;   (illegal)

         int i; for(i<0;i<100;++i){}; j = i;   (ok)

         for(int i=0;i<100;i++){}  for(i=0;i<100;i++){} (illegal)

         for(int i=0;i<100;i++){}  for(int i=0;i<100;i++){} (ok)

 

20, STL里的iterator 不要直接传递给指针。或把指针传给iterator

         string s; char *p = s.begin(); (illegal)

         string s; char *p = const_cast<char *>(s.c_str()); (ok)

//below example is illegal

         map<LPCTSTR,LPTSTR>::iterator p = NULL;

         p = m_mpUrlParams.find(lpTempID);

         if(p != NULL){…}

//below example is right

         map<LPCTSTR,LPTSTR>::iterator p = m_mpUrlParams.find(lpTempID);

         if(p != m_mpUrlParams.end()){…}

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)
{

     if (container.size() >= 2)

    {

         typename C::const_iterator iter(container.begin());
        ...
     }
}

22, typedef 必须是public才能被外界访问到.

23, 在如下情况下必须明确指定模板参数

template< class TBase, class TWinTraits = CControlWinTraits >

class UI_EXPORT CTriSimplestWndImpl : public CWindowImpl<CTriSimplestWndImpl , TBase, TWinTraits>

{

public:

         BEGIN_MSG_MAP(CTriSimplestWndImpl)

         END_MSG_MAP()

};

 

template< class TBase, class TWinTraits = CControlWinTraits >

class UI_EXPORT CTriSimplestWndImpl : public CWindowImpl<CTriSimplestWndImpl<TBase,TWinTraits>, TBase, TWinTraits>

{

public:

         BEGIN_MSG_MAP(CTriSimplestWndImpl)

         END_MSG_MAP()

};

还有很多warning应该去关注,争取做到无warning

posted on 2010-05-28 10:48  飞天名猪  阅读(910)  评论(0编辑  收藏  举报