• <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>
            DLL導(dǎo)出類

              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)用工程中沒有定義DLL_FILE,故其包含point.h和circle.h后引入的類聲明為:

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

            {



            }


              和

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

            {



            }


            Posted on 2005-11-25 18:26 艾凡赫 閱讀(11353) 評(píng)論(0)  編輯 收藏 引用 所屬分類: DLL 技術(shù)
            人妻无码久久精品| 精品综合久久久久久97超人| 久久综合鬼色88久久精品综合自在自线噜噜 | 久久久久无码精品| 亚洲欧洲精品成人久久曰影片 | 色婷婷久久综合中文久久一本| 久久精品亚洲男人的天堂| 久久久久久久97| 久久久午夜精品| 精品一区二区久久久久久久网站| 久久综合精品国产一区二区三区| 伊人久久大香线蕉综合Av| 国内精品久久久久久久亚洲| 一本色道久久综合亚洲精品| 久久精品国产亚洲Aⅴ香蕉 | 色8激情欧美成人久久综合电| 午夜天堂精品久久久久| 亚洲а∨天堂久久精品9966| 精品久久久久久国产91| 久久久久亚洲AV无码专区首JN| 精品久久香蕉国产线看观看亚洲| 国产精品久久久久蜜芽| 久久久久人妻一区精品| 久久国产视屏| 久久精品一区二区三区不卡| 久久精品国产精品亚洲精品| 久久se精品一区二区影院 | 欧美精品国产综合久久| 久久精品国产一区二区电影| 久久精品国产久精国产| 久久国产色AV免费看| 久久久噜噜噜久久中文福利| 无码国内精品久久综合88| 亚洲国产婷婷香蕉久久久久久| 大美女久久久久久j久久| www性久久久com| 2020久久精品国产免费| 国产精品久久久久久| 久久99精品国产| 精品久久久久久国产牛牛app| 国产一区二区精品久久岳|