c++ primer读书笔记(五)

一、知识要点

1、使用空语句时,应加注释,以便知晓此处是故意省略的

2、指针的size

       int value[] = {1, 2, 3, 4, 5};

       int *p = value;

       size_t sz = sizeof(p) / sizeof(*p);

3、调试方法

      int main

      {

       #ifndef NDEBUG

             cout << "run to here" << endl; //如果程序中未定义NDEBUG,则执行这句,可通过此方法添加调试语句,并通过

                                                                          #define NDEBUG使调试语句不执行

       #endif 

        }

二、遗留

1、assert

2、异常

三、工作收获

今天学习了如何使用VS2008创建动态链接库并使用

a.打开Visual Studio 2008,File -> New -> Project…,选择Win32 Console Application,Name设置为test.

b.Application type设置为dll,勾选Empty project,单击Finish按钮

c.新建test.h文件,内容如下:

   #ifndef  TEST_H

   #define TEST_H

   #ifdef TEST_BUILD

   #define TEST_DLL __declspec(dllexport)

   #else

   #define TEST_DLL __declspec(dllimport)

   #endif

 

   class TEST_DLL MyTest

   {

   public: 

       int __stdcall add(int x, int y);

   };

   #endif

d.新建test.cpp文件,内容如下:

   #include "test.h"

   #define TEST_BUILD

 

   int __stdcall MyTest::add(int x, int y)

   {

   return (x+y);

   }

e.分别在Debug和Release模式下编译,这时在文件夹test\Debug和test\Release内都有test.dll和test.lib文件,将test\Debug里面的      test.lib重新命名为testd.lib。只需保留test\Release中的dll文件。test.dll,testd.lib,test.lib和test.h就是我们使用这个动态库所需的文件。在使用这个动态库的代码中添加:

      #ifdef _DEBUG

     #pragma comment(lib, "testd.lib")

     #else

    #pragma comment(lib, "test.lib")

   #endif

——————————

回家跳操,走起~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值