类的构造函数 类型一样 变量名不一样无所谓

// 你必须定义一个 `main()` 函数入口。
#include <iostream>
using namespace std;
#include <string.h>
typedef const char* FX_LPCSTR;
typedef char FX_CHAR;
typedef int FX_STRSIZE;
typedef int FX_BOOL;
typedef unsigned char FX_BYTE;
 
#define FX_Alloc(type, size)						(type*)calloc(size, sizeof(type))
#define FX_Free(ptr)								free(ptr)
struct CFX_StringData {
    long		m_nRefs;
    FX_STRSIZE	m_nDataLength;
    FX_STRSIZE	m_nAllocLength;
    FX_CHAR		m_String[1];
};
static CFX_StringData* FX_AllocString(int nLen)
{
    // |nLen| is currently declared as in |int|. TODO(palmer): It should be
    // a |size_t|, or at least unsigned.
 if (nLen == 0 || nLen < 0) {
        return NULL;
    }
    int nSize = nLen;
    nSize += sizeof(long) * 3 + 1;
    CFX_StringData* pData = (CFX_StringData*)FX_Alloc(FX_BYTE, nSize);
    if (!pData) {
        return NULL;
    }
    pData->m_nAllocLength = nLen;
    pData->m_nDataLength = nLen;
    pData->m_nRefs = 1;
    pData->m_String[nLen] = 0;
    return pData;
}
 static void FX_ReleaseString(CFX_StringData* pData)
{
    if (pData == NULL) {
        return;
    }
    pData->m_nRefs --;
    if (pData->m_nRefs <= 0) {
        FX_Free(pData);
    }
}




class CFX_Object
{
  public:
  void* operator new(size_t size, FX_LPCSTR file, int line)
  {
    return malloc(size);
  }
   
  void operator delete(void*p,FX_LPCSTR file,int size)
  {
    free(p);
  }
  void* operator new(size_t size)
  {
    return malloc(size);
  }
  void operator delete(void* p)
  {
    free(p);
  }
    void*			operator new[] (size_t size, FX_LPCSTR file, int line)
    {
        return malloc(size);
    }
    void			operator delete[] (void* p, FX_LPCSTR file, int line)
    {
        free(p);
    }
    void*			operator new[] (size_t size)
    {
        return malloc(size);
    }
    void			operator delete[] (void* p)
    {
        free(p);
    }
    void*			operator new (size_t, void* buf)
    {
        return buf;
    }
    void			operator delete (void*, void*)							{}
};
 
 
class CFX_ByteString : public CFX_Object
{
public:
   CFX_ByteString(FX_LPCSTR ptr, FX_STRSIZE len = -1);
protected:
    struct CFX_StringData*	m_pData;
    void					AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const;
};
 
CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen)
{
    if (nLen < 0) {
        nLen = lpsz ? (FX_STRSIZE)strlen(lpsz) : 0;
    }
    if (nLen) {
        m_pData = FX_AllocString(nLen);
        if (m_pData) {
            memcpy(m_pData->m_String, lpsz, nLen);
        }
    } else {
        m_pData = NULL;
    }
}
 

void CFX_ByteString::AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const
{
  return;
}

int main()
{
 
  cout << sizeof(CFX_StringData) << endl;
  return 0;
}
 
		

  

上一篇:CFX_BasicArray


下一篇:CFX_StringData getbuffer