繁体   English   中英

模板类CArray在gcc下编译,错误:未声明用作函数参数的类

[英]Template class CArray compile under gcc, Error: the class which used as a parameter of a function undeclared

#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

在模板类CArray的CreateArray函数中, gcc编译器尚未声明CAllocator 但是所有代码都在vs2010下工作

请帮助,谢谢大师 在此处输入图片说明

请停止命名_ALLOCATOR_H 名称以___开头,后跟一个大写字母,供编译器和标准使用。 –丹

将#ifndef _ALLOCATOR_H #define _ALLOCATOR_H更改为#ifndef ALLOCATOR_H #define ALLOCATOR_H一切正常! 谢谢大家-杰克

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM