請看看這個代碼並運行它:
我發現了非常奇怪的錯誤:
錯誤1個錯誤C2663:「分配器:: allocate_help」:2個重載沒有'this'指針的合法轉換沒有法律轉化爲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;
}
我完全不明白這個err味精。希望有人能幫助我。謝謝。
無法按照您的要求進行編譯。 `Int2Type`沒有被聲明/定義 – 2010-11-30 20:02:56