c – 没有合法转换为’this’指针

前端之家收集整理的这篇文章主要介绍了c – 没有合法转换为’this’指针前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
请查看此代码并运行它:
我收到了很奇怪的错误
错误1错误C2663:’Allocator :: allocate_help’:2个重载没有’this’指针的合法转换
template<class FailureSignal>
class Allocator
{
private:
    template<class Exception,class Argument>
    void allocate_help(const Argument& arg,Int2Type<true>)
    {
    }

    template<class Exception,class Argument>
    std::nullptr_t allocate_help(const Argument& arg,Int2Type<false>)
    {
        return nullptr;
    }

public:
    template<class T>
    void Allocate(signed long int nObjects,T** ptr = 0)const
    {
    allocate_help<std::bad_alloc>(1,Int2Type<true>());  
    }

};

int _tmain(int argc,_TCHAR* argv[])
{
    Allocator<int> all;
    all.Allocate<int>(1);
    return 0;
}
@H_502_6@我绝对不明白这个错误的消息.希望有人可以帮助我.谢谢.

解决方法

我注意到Allocate被声明为const但是allocate_help不是 – 这可能与问题有关吗?
原文链接:https://www.f2er.com/c/119862.html

猜你在找的C&C++相关文章