GCC 4.2 Strange Bug Template

I have the following code compiled with GCC 4.2 / Xcode.

template <typename T>
class irrProcessBufferAllocator
{
public:

    T* allocate(size_t cnt)
    {
        return allocProcessBufferOfType<T>(cnt);
    }

    void deallocate(T* ptr)
    {
        if (ptr)
        {
            releaseProcessBuffer(ptr);
        }
    }

    void construct(T* ptr, const T& e)
    {
        new ((void*)ptr) T(e);//"error: expected type-specifier before 'e' " and
//error: expected `;' before 'e'
    }

    void destruct(T* ptr)
    {
        ptr->~T();//error: expected class-name before ';' token
    }

};

I really can't figure out how to fix the errors. please, help,

Thank.

+1
source share
3 answers

Just to make sure that you are missing, you need: <cstddef>for std::size_tand <new>to post a new one?

Otherwise, these functions look correct. If this is an entire dispenser, it has other disadvantages, such as missing required typedefs, methods, address()and max_size(), as well as a template rebind.


Edit: The only cause of the error may be that you have a function type macro installed.

#define T(z) zzz

T(), , T, .

.

+3

?

template <class T> 
class irrProcessBufferAllocator 
{ 
public: 

    T* allocate(size_t cnt) 
    { 
        return allocProcessBufferOfType<T>(cnt); 
    } 

    void deallocate(T* ptr) 
    { 
        if (ptr) 
        { 
            releaseProcessBuffer(ptr); 
        } 
    } 

    void construct(T* ptr, const T& e) 
    { 
        new ((void*)ptr) T(e);//"error: expected type-specifier before 'e' " and 


        //error: expected `;' before 'e' 
    } 

    void destruct(T* ptr) 
    { 
        ptr->~T();//error: expected class-name before ';' token 
    } 
};

int main(){
    irrProcessBufferAllocator<int> i, j;
    int *p = new int;
    i.construct(p, 2);
    i.destruct(p);
}
0

This simply indicates a problem, does not fix it. I specialized the template for all types of PODs, removing "new" and "-> ~ T ()" from the construction and destruction functions. Errors still appear in the same place.

0
source

All Articles