One, C + + customers reuse C + + objects
Suppose you already have a class that you can reuse, we can reuse it in our own program, just add its definition and implementation file to our own project, and include this type of definition file in the file that uses it, which is our most common method of C + + standard reuse. On my own, I encountered the better control code on CodeProject, so I used it directly to my project.
Here's the first code example of my series, and in the next few articles, the code will continue to improve from C + + to COM.
A brief introduction to the C + + object We want to reuse is a simple database-like object that manages the data in memory, which contains an array of pointers to all the tables in the database, which is actually an array of strings, each representing a row of the table. In addition, this class contains an array of table names for the data table.
DBSRV.h file:
typedef long hresult;//simulate HRESULT in COM
Memory Database Classes
Class CDB
{
Interfaces
Public
Interface for data access
HRESULT Read (short ntable, short nrow, LPTSTR lpszdata)/Read data, ntable specify data table, nrow specify data row
HRESULT Write (short ntable, short nrow, LPCTSTR lpszdata)/write data, ntable specify data table, nrow specify data rows
Interface for database management
HRESULT Creation (short &ntable, LPCTSTR lpszname);//create datasheet with table named Lpszname
HRESULT Delete (short ntable);//Delete datasheet
Interface for database information
HRESULT getnumtables (short &nnumtables);//Get Data table count
HRESULT Gettablename (short ntable, LPTSTR lpszname);//get the specified datasheet table name, ntable as the data table index number
HRESULT getnumrows (short ntable, short &nrows); Gets the number of data rows for the specified data table, ntable to the data table index number, and nrows the number of rows returned
Implementation
Private
CPtrArray M_arrtables; An array of pointers to all tables in the database
CStringArray M_arrnames; Array of data table names
Public
~CDB ();
};