当前位置:编程学习 > C/C++ >>

C++ 数据库操作

一、整体代码
      01.cpp
 
#include <iostream>  
using namespace std;  
class DBHelper  
{  
public:  
    DBHelper()  
    {  
        cout<<"DB ..."<<endl;  
    }  
    ~DBHelper()  
    {  
        cout<<"~DB ..."<<endl;  
    }  
    void Open()  
    {  
        cout<<"Open ..."<<endl;  
    }  
    void Close()  
    {  
        cout<<"Close ..."<<endl;  
    }  
    void Query()  
    {  
        cout<<"Query ..."<<endl;  
    }  
};  
class DB  
{  
public:  
    DB()  
    {  
        db_ = new DBHelper;  
    }  
    ~DB()  
    {  
        delete db_;  
    }  
    DBHelper* operator->()  
    {  
        return db_;  
    }  
private:  
    DBHelper* db_;  
};  
int main(void)  
{  
    DB db;  
    db->Open();//db operaot->().Open()  
    db->Query();  
    db->Close();  
    return 0;  
}  

 


补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,