gpt4 book ai didi

c++ - 无法合法转换为 'this' 指针

转载 作者:可可西里 更新时间:2023-11-01 18:22:00 25 4
gpt4 key购买 nike

请看一下这段代码并运行它:
我遇到了非常奇怪的错误:
错误 1 ​​error C2663: 'Allocator::allocate_help' : 2 overloads have no legal conversion for 'this' pointer

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;
}

我绝对不明白这个错误消息。希望有人可以帮助我。谢谢你。

最佳答案

我注意到 Allocate 被声明为 constallocate_help 不是 - 这可能与问题有关吗?

关于c++ - 无法合法转换为 'this' 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4317814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com