xyxfly的专栏

每个人都有潜在的能量,只是很容易:被习惯所掩盖,被时间所迷离,被惰性所消磨。

用户操作
[即时聊天] [发私信] [加为好友]
xyxflyID:xyxfly
2740次访问,排名2万外好友0人,关注者6
xyxfly的文章
原创 7 篇
翻译 0 篇
转载 1 篇
评论 24 篇
xyxfly的公告
月 [下月] [上月]
QQ:39940649
最近评论
443:如果是sql2005 从excel里面读数据会提示要将某个设置打开,有没有方法?
443:bu cuo
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 抽象类和接口收藏

    新一篇: SQL与EXCEL互导 | 旧一篇: SQL语句总结一(MS SQL Server)

        C++中抽象类是带一个或者多个纯虚函数的类,纯虚函数没有函数体。

        接口基础:一组定义了参数和返回类型,没有实现的函数。

        在客户端,客户使用的是接口指针,而不是具体的类指针。

    实例:

    DLL.dll

    // CreditVerification.h
    #pragma once

    #ifdef _DLL
    #define DLLSPEC __declspec (dllexport)
    #else
    #define DLLSPEC __declspec (dllimport)
    #endif

    struct ICreditVerification
    {
     virtual void SetCardType(char* s) = 0;
     virtual bool VerifyCardNumber(long n) = 0;
    };

    DLLSPEC ICreditVerification* GetCreditVerificationObject(); 

    // CreditVerification.cpp

    #define _DLL
    #include "creditverification.h"
    #include <windows.h>

    BOOL APIENTRY DllMain(HANDLE hModule,
     DWORD  ul_reason_for_call, LPVOID lpReserved)
    {
        return TRUE;
    }

    class CCreditVerification : public ICreditVerification
    {
    private:
     enum CardType {Visa, MasterCard, Amex} m_type;
    public:
     void SetCardType(char* s)
     {
      if (0 == strcmp("Visa", s))
       m_type = Visa;
      else if (0 == strcmp("MasterCard", s))
       m_type = MasterCard;
      else m_type = Amex;
     }
     bool VerifyCardNumber(long n)
     {
      if (m_type == Visa)
       return (n % 2);
      else if (m_type == MasterCard)
       return (n % 3);
      else if (m_type == Amex)
       return (n % 5);
      else return false;
     }
    };

    DLLSPEC ICreditVerification* GetCreditVerificationObject()
    {
     return new CCreditVerification;
    }

    DLLTest.exe

    // Test.cpp
    #include "CreditVerification.h"
    #include <windows.h>
    #include <tchar.h>
    #pragma comment(lib,"DLL.lib")

    int _tmain(int argc, _TCHAR* argv[])
    {
     ICreditVerification* c = GetCreditVerificationObject();
     c->SetCardType("MasterCard");
     if (c->VerifyCardNumber(1234))
      MessageBox(0, "Card Verified", "OK", 0);
     else
      MessageBox(0, "Card Rejected", 0, 0);

     return 0;
    }

    发表于 @ 2006年07月24日 20:26:00|评论(loading...)|编辑

    新一篇: SQL与EXCEL互导 | 旧一篇: SQL语句总结一(MS SQL Server)

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © xyxfly