2015-12-15 37 views
0
#ifndef _ALLOCATOR_H 
#define _ALLOCATOR_H 


#include "ace/OS_NS_stdio.h" 
#include "ace/OS_NS_string.h" 


#include "ace/MMAP_Memory_Pool.h" 
#include "ace/Malloc_T.h" 
#include "ace/Null_Mutex.h" 
#include "ace/PI_Malloc.h" 

#include "ace/OS_NS_unistd.h" 
#include "ace/Thread_Mutex.h" 
#include "ace/Process_Mutex.h" 

#include <string> 
using namespace std; 

class CAllocator 
{ 
public: 
    CAllocator(); 
    ~CAllocator(void); 

public: 
     bool Create(char* strPoolName); 
     void Destroy(); 

public: 
     char* NewMem(char* strBlockName,int nBlockSize); 
     char* FindMem(char* strBlockName); 
     bool FreeMem(char* strBlockName); 

private: 
     typedef ACE_Malloc_T <ACE_MMAP_MEMORY_POOL, 
       ACE_Process_Mutex, 
       ACE_PI_Control_Block> 
       ALLOCATOR; 

     ALLOCATOR* m_pAllocator; 
}; 


#endif //_ALLOCATOR_H 


#ifndef _ARRAY_H 
#define _ARRAY_H 

#include "allocator.h" 

template<typename T> 
class CArray 
{ 
public: 
    bool CreateArray(CAllocator* pAllocator,char* strArrayName,int nArraySize);  
    bool OpenArray(CAllocator* pAllocator,char* strArrayName); 
public: 
    CArray() 
    { 
     m_pArrayData = NULL;  
    }           

    ~CArray() 
    { 
     m_pArrayData = NULL; 
    } 

public: 
    T*  GetObject(int nIndex); 
    int GetArraySize(); 

private: 
    T*  m_pArrayData; 
}; 

#include "array.cpp" 
#endif //_ARRAY_H 

在功能CreateArray模板類CARRAY的, 的gcc編譯器一個函數的參數類說CAllocator一直沒有宣稱爲。 但所有的代碼下VS2010工作模板類CARRAY下GCC編譯錯誤:它用作未申報

請大家幫幫忙,謝謝大師 enter image description here

+1

請停止命名,如'_ALLOCATOR_H'。名稱以'__'或'_'開頭,後跟一個大寫字母保留供編譯器和標準使用。 – Danh

+1

請發佈[MCVE](http://stackoverflow.com/help/mcve)。 –

+0

變化 的#ifndef _ALLOCATOR_H 的#define _ALLOCATOR_H 到 的#ifndef ALLOCATOR_H 的#define ALLOCATOR_H 一切OK! 謝謝大家 – Jack

回答

0

請停止類似的命名_ALLOCATOR_H。名稱以___後跟一個大寫字母開頭,保留供編譯器和標準使用。 –   DANH

變化的#ifndef _ALLOCATOR_H的#define _ALLOCATOR_H到的#ifndef ALLOCATOR_H的#define ALLOCATOR_H一切OK!謝謝大家 - Jack