// ifaststring.h///////////////////
class _declspec(dllexport)IFastString { public: virtual void Delete(void) = 0; virtual int Length(void) = 0; virtual int Find(const char *psz) = 0; };
extern "C" IFastString *CreateFastString(const char *psz); ////////////////////////////////////////////////////////////
// ifaststring.h ///////////////////
#include"ifaststring.h"
class FastString:public IFastString { private: const int m_cch; //number of character char *m_psz; public: FastString(const char *psz); ~FastString(void); int Length(void); int Find(const char *psz); void Delete(void); }; /////////////////////////////////////////
// faststring.cpp////////////////////// #include<string> #include"faststring.h"
IFastString *CreateFastString(const char *psz) { return new FastString(psz); }
FastString::FastString(const char* psz):m_cch(strlen(psz)), m_psz(new char[strlen(psz)+1]) { strcpy(m_psz, psz); }
FastString::~FastString(void) { delete[] m_psz; }
void FastString::Delete(void) { delete this; }
int FastString::Length(void) { return m_cch; }
int FastString::Find(const char *psz) //the function is not complete { return 1; }
///////////////////////////////////////////////////////////////////////////
// mainTest.cpp//////////// #include"ifaststring.h" #include<iostream>
using namespace std;
int f(void) { int n = -1; IFastString *pfs = CreateFastString("Hi Bob"); if( pfs->Find("g") ) { cout<<" test success! "<<endl ; } return 2; }
int main( ) { int m; m = f(); cout<<m;
return 0; } //////////////////////////////////////////// |