• <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>

            醬壇子

            專注C++技術(shù) 在這里寫下自己的學(xué)習(xí)心得 感悟 和大家討論 共同進(jìn)步(歡迎批評(píng)!!!)

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              66 Posts :: 16 Stories :: 236 Comments :: 0 Trackbacks

            公告

            王一偉 湖南商學(xué)院畢業(yè) 電子信息工程專業(yè)

            常用鏈接

            留言簿(19)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            積分與排名

            • 積分 - 387834
            • 排名 - 64

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            DLL導(dǎo)出類(轉(zhuǎn))

              DLL中定義的類可以在應(yīng)用工程中使用。

              下面的例子里,我們?cè)贒LL中定義了point和circle兩個(gè)類,并在應(yīng)用工程中引用了它們(單擊此處下載本工程附件)。

            //文件名:point.h,point類的聲明

            #ifndef POINT_H

            #define POINT_H

            #ifdef DLL_FILE

            class _declspec(dllexport) point //導(dǎo)出類point

            #else

            class _declspec(dllimport) point //導(dǎo)入類point

            #endif

            {

            public:

            float y;

            float x;

            point();

            point(float x_coordinate, float y_coordinate);

            };

            #endif


            //文件名:point.cpp,point類的實(shí)現(xiàn)

            #ifndef DLL_FILE

            #define DLL_FILE

            #endif

            #include "point.h"

            //類point的缺省構(gòu)造函數(shù)

            point::point()

            {

            x = 0.0;

            y = 0.0;

            }

            //類point的構(gòu)造函數(shù)

            point::point(float x_coordinate, float y_coordinate)

            {

            x = x_coordinate;

            y = y_coordinate;

            }


            //文件名:circle.h,circle類的聲明

            #ifndef CIRCLE_H

            #define CIRCLE_H

            #include "point.h"

            #ifdef DLL_FILE

            class _declspec(dllexport)circle //導(dǎo)出類circle

            #else

            class _declspec(dllimport)circle //導(dǎo)入類circle

            #endif

            {

            public:

            void SetCentre(const point ¢rePoint);

            void SetRadius(float r);

            float GetGirth();

            float GetArea();

            circle();

            private:

            float radius;

            point centre;

            };

            #endif


            //文件名:circle.cpp,circle類的實(shí)現(xiàn)

            #ifndef DLL_FILE

            #define DLL_FILE

            #endif

            #include "circle.h"

            #define PI 3.1415926

            //circle類的構(gòu)造函數(shù)

            circle::circle()

            {

            centre = point(0, 0);

            radius = 0;

            }

            //得到圓的面積

            float circle::GetArea()

            {

            return PI *radius * radius;

            }

            //得到圓的周長(zhǎng)

            float circle::GetGirth()

            {

            return 2 *PI * radius;

            }

            //設(shè)置圓心坐標(biāo)

            void circle::SetCentre(const point ¢rePoint)

            {

            centre = centrePoint;

            }

            //設(shè)置圓的半徑

            void circle::SetRadius(float r)

            {

            radius = r;

            }

            類的引用:

            #include "..\circle.h"  //包含類聲明頭文件

            #pragma comment(lib,"dllTest.lib");


            int main(int argc, char *argv[])

            {

            circle c;

            point p(2.0, 2.0);

            c.SetCentre(p);

            c.SetRadius(1.0);

            printf("area:%f girth:%f", c.GetArea(), c.GetGirth());


            return 0;

            }


              從上述源代碼可以看出,由于在DLL的類實(shí)現(xiàn)代碼中定義了宏DLL_FILE,故在DLL的實(shí)現(xiàn)中所包含的類聲明實(shí)際上為:

            class _declspec(dllexport) point //導(dǎo)出類point

            {



            }


              和

            class _declspec(dllexport) circle //導(dǎo)出類circle

            {



            }


              而在應(yīng)用工程中沒(méi)有定義DLL_FILE,故其包含point.h和circle.h后引入的類聲明為:

            class _declspec(dllimport) point //導(dǎo)入類point

            {



            }


              和

            class _declspec(dllimport) circle //導(dǎo)入類circle

            {



            }


            posted on 2006-12-13 12:13 @王一偉 閱讀(5652) 評(píng)論(3)  編輯 收藏 引用

            Feedback

            # re: DLL導(dǎo)出類 2007-03-26 15:58 馮博
            問(wèn)大俠,如果類中含有友元怎么做?我的總是出錯(cuò)~~
            我是這么寫的:
            #ifdef DLL_FILE
            _declspec(dllexport) friend std::ostream& operator<<(std::ostream& os,Circle& c)
            #else
            _declspec(dllimport) friend std::ostream& operator<<
            (std::ostream& os,Circle& c)
            #endif
            {
            os<<"some thing";
            return os;
            }

            每次主文件里cout << circle的時(shí)候就當(dāng)?shù)袅藒~
            my email:vonboo@163.com  回復(fù)  更多評(píng)論
              

            # re: DLL導(dǎo)出類 2007-08-11 11:14 filebat
            可不可以在沒(méi)有l(wèi)ib只有dll的情況下,使用dll中的類?  回復(fù)  更多評(píng)論
              

            # re: DLL導(dǎo)出類 2007-08-11 13:15 SmartPtr
            @filebat
            兩個(gè)好問(wèn)題, 期待樓主解答  回復(fù)  更多評(píng)論
              


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久精品国产精品青草app| 久久影院午夜理论片无码| 91精品观看91久久久久久| 97精品伊人久久大香线蕉app| 94久久国产乱子伦精品免费| 久久精品国产亚洲精品2020| 久久精品www| 国产99久久久久久免费看| 人妻少妇久久中文字幕| 亚洲精品tv久久久久| 精品久久久久久久| 久久国产热这里只有精品| 丰满少妇人妻久久久久久4| 国产日韩久久免费影院| 亚洲午夜精品久久久久久app| 亚洲∧v久久久无码精品| 久久久久亚洲av成人无码电影| 无码国内精品久久人妻麻豆按摩 | 久久九九精品99国产精品| 久久免费线看线看| 亚洲va久久久噜噜噜久久| 91精品日韩人妻无码久久不卡| 岛国搬运www久久| 午夜久久久久久禁播电影| 久久久久香蕉视频| 久久久久久亚洲AV无码专区| 精品久久久久中文字幕一区| 久久国产精品99精品国产987| 精品国产乱码久久久久软件| 久久精品国产72国产精福利| 国产色综合久久无码有码| 精品久久久无码21p发布| 久久久久久曰本AV免费免费| 2021少妇久久久久久久久久| 久久青青色综合| 伊人久久综合无码成人网| 久久久久久国产精品美女 | 少妇高潮惨叫久久久久久| 国产精品99久久久精品无码| 久久久久国产视频电影| 精品久久人人爽天天玩人人妻|