• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Impossible is nothing  
              愛過知情重醉過知酒濃   花開花謝終是空   緣份不停留像春風來又走   女人如花花似夢
            公告
            日歷
            <2006年4月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456
            統(tǒng)計
            • 隨筆 - 8
            • 文章 - 91
            • 評論 - 16
            • 引用 - 0

            導航

            常用鏈接

            留言簿(4)

            隨筆分類(4)

            隨筆檔案(8)

            文章分類(77)

            文章檔案(91)

            相冊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

             

            1.CTypedPtrList<CObList, CDrawObj*> 與 std::vector<CDrawObj*>
            如果CDrawObj*從COject繼承用CTypedPtrList優(yōu)于用std::vector,雖然std::vector很優(yōu)美,但在
            MFC下,MFC類是大房,std::vector是小妾,很多MFC類的功能std::vector用不了,CTypedPtrList可以.
            比如直接的容器序列化,如果使用std::vector的話,你的工作將很多,保存時需遍歷對象,一個一個保存,讀取時你要知道對象的具體類型(繼承的最末端),然后創(chuàng)建對象,一個一個讀取.

            typedef CTypedPtrList<CObList, CMyObject*>  CMyList;
            CMyList ml;
            CMyObject* pMyObject = new CMyObject();
            ml.AddTail(pMyObject);

            CFileException e;
            CFile myFile;
            myFile.Open("MyFile.txt", CFile::modeCreate|CFile::modeWrite, &e);
            CArchive ar(&myFile, CArchive::store);
            ml.Serialize(ar);

            ar.Close();
            myFile.Close();

            while (!ml.IsEmpty())
            {
               delete ml.GetHead();
               ml.RemoveHead();
            }
            //=====================
            //where CMyObject is defined by the following files:

            //CMyObject.h
            class CMyObject : public CObject
            {
            public:
                 int i;
                 void Serialize(CArchive& ar);
                 CMyObject() { i = 9876;}
            protected:
                 DECLARE_SERIAL(CMyObject)
            };

            //===================
            //CMyObject.cpp
            #include "stdafx.h"
            #include "CMyObject.h"

            IMPLEMENT_SERIAL(CMyObject, CObject, 0) 

            void CMyObject::Serialize(CArchive& ar)
            {
                CObject::Serialize( ar );
                if( ar.IsStoring() )
                     ar << i;
                else
                     ar >> i;
            }
            2.析構函數(shù)可以自己調用
            比較吃驚!
            但msdn上是這樣說的
            Calling a destructor explicitly is seldom necessary. However, it can be useful to perform cleanup of objects placed at absolute addresses. These objects are commonly allocated using a user-defined new operator that takes a placement argument. The delete operator cannot deallocate this memory because it is not allocated from the free store . A call to the destructor, however, can perform appropriate cleanup. To explicitly call the destructor for an object, s, of class String, use one of the following statements:
            s.String::~String();     // Nonvirtual call
            ps->String::~String();   // Nonvirtual call

            s.~String();       // Virtual call
            ps->~String();     // Virtual call

            自己測試的代碼
            #include <iostream>

            using namespace std;
            class ExplicitlyCallDesCtor
            {
            public:
             ExplicitlyCallDesCtor()
             {
              cout << "call Constructor" << endl;
             }
             ~ExplicitlyCallDesCtor()
             {
              cout << "call Destructor" << endl;
             }
            private:
             int member;

            };
            int main()
            {
             {
              ExplicitlyCallDesCtor  o;
              cout << "befor Explicitly call" << endl;
              o.~ExplicitlyCallDesCtor();
              cout << "after Explicitly call" << endl;
              cout << "Exit the scope" << endl;
             }
                cout << "Systemc all" << endl;
            }
            結果:
            call Constructor
            befor Explicitly call
            call Destructor
            after Explicitly call
            Exit the scope
            call Destructor
            Systemc all
            microsoft c++ compiler 13 與 GCC 3.4.2下結果相同

            3.注意一個不易發(fā)現(xiàn)的死循環(huán)
            std::vector<int> IntS;
            ints.pushback(...)
            for (UINT i=IntS.size()-1;i>=0;i--)
            {
            ....
            }


             

            posted on 2006-03-03 16:45 笑笑生 閱讀(1325) 評論(3)  編輯 收藏 引用
            評論:
            • # re: 工作中發(fā)現(xiàn)的  …… Posted @ 2006-03-03 16:54
              3.注意一個不易發(fā)現(xiàn)的死循環(huán)
              無語了……
              無符號數(shù)當然不小于0了  回復  更多評論   

            • # re: 工作中發(fā)現(xiàn)的  蟲子 Posted @ 2006-03-03 16:57
              STL的序列化可以參看一下boost的序列化庫。
              如果你的工作都是在windows下的話,MFC是一個非常合適而且有效的庫平臺。
                回復  更多評論   

            • # re: 工作中發(fā)現(xiàn)的  Stone Jiang Posted @ 2006-04-13 09:17
              0也屬于無符號數(shù)呀   回復  更多評論   

             
            Copyright © 笑笑生 Powered by: 博客園 模板提供:滬江博客
            久久99精品久久久久久9蜜桃| 国内精品伊人久久久久网站| 无码任你躁久久久久久老妇App| 合区精品久久久中文字幕一区| 精品久久久久久中文字幕大豆网| 九九久久自然熟的香蕉图片| 精品999久久久久久中文字幕| 青草影院天堂男人久久| 久久涩综合| 天堂久久天堂AV色综合| 久久国产成人午夜aⅴ影院| 99久久香蕉国产线看观香| 99久久成人18免费网站| 色诱久久久久综合网ywww| 久久伊人亚洲AV无码网站| 久久国产色AV免费观看| 中文字幕热久久久久久久| 国产高清美女一级a毛片久久w | 人人狠狠综合久久亚洲88| 人妻精品久久久久中文字幕| 久久精品无码一区二区三区| 久久中文字幕人妻熟av女| 久久激情五月丁香伊人| 伊人久久免费视频| 69SEX久久精品国产麻豆| 亚洲精品国精品久久99热一| 一级做a爰片久久毛片毛片| 国产国产成人久久精品| 99热精品久久只有精品| 久久久久久久99精品免费观看| 亚洲熟妇无码另类久久久| 久久国产AVJUST麻豆| 国产精品久久久久久久久久影院 | 欧洲性大片xxxxx久久久| 国内精品久久久久久不卡影院| 99久久超碰中文字幕伊人 | 久久精品国产精品亚洲人人| 爱做久久久久久| 精品久久综合1区2区3区激情| 国产高清国内精品福利99久久| 99久久成人18免费网站|