GCC 4.2模板奇怪的错误 [英] GCC 4.2 Template strange error

查看:100
本文介绍了GCC 4.2模板奇怪的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用GCC 4.2 / XCode编译的以下代码。

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,

感谢。

推荐答案

确保你不缺少必要的包括:< cstddef> for std :: size_t < new> for placement new?

Just to make sure, you are not missing necessary includes: <cstddef> for std::size_t and <new> for placement new?

否则,这些函数看起来是正确的。如果这是整个分配器,它有其他缺陷,如缺少必需的typedef, address() max_size()方法,以及 rebind 模板。

Otherwise those functions would appear to be correct. If that is the entire allocator, it has other flaws, such as missing required typedefs, address() and max_size() methods, as well as a rebind template.

:错误的唯一原因可能是你定义了一个函数式宏T。

The only cause for the error could be that you have a function-style macro T defined.

#define T(z) zzz

会使预处理器替换所有 T()它遇到,但留下 T s后面没有括号。

would make the preprocessor replace all T()'s it encounters, but leave the Ts not followed by brackets.

您可以重命名模板参数。

You could just rename the template argument.

这篇关于GCC 4.2模板奇怪的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆