请看一下这段代码然后运行它:
我得到了非常奇怪的错误:
错误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;
}
Run Code Online (Sandbox Code Playgroud)
我绝对不明白这个错误的消息.希望有人可以帮助我.谢谢.
fbr*_*eto 12
我注意到Allocate已经宣布const但allocate_help不是 - 这可能与问题有关吗?