2017-01-16 2 views
2

무엇 :: 줄에 : return :: operator new (size, :: std :: nothrow); 왜 이런::글로벌operator newoperator delete 함수가 호출되는 것을 의미 범위 결정 연산자를 사용하여 템플릿 형 TC에서 범위 해결 연산자에 대한 혼동

template<typename T> 
class DefaultMemoryAllocator 
{ 
public: 
    static inline void *Allocate(size_t size) 
    { 
    return ::operator new(size, ::std::nothrow); 
    } 
    static inline void Deallocate(void *pointer, size_t size) 
    { 
    ::operator delete(pointer); 
    } 
}; 
+1

"범위 분석 연산자"입니다. 그 이유는 여기에 설명되어 있습니다. http://stackoverflow.com/questions/4173254/what-is-the-curiously-recurring-template-pattern-crtp – StoryTeller

답변

1

에 대한 사용이없는 경우 클래스가 같은 템플릿을 사용하고 있습니다 그 계급을 위해 무시되었을지도 모른 것에 반대했다.

이 함수는 메모리 정책 클래스의 일부이며, 재정의 된 함수 인 'operator newoperator delete 클래스에서 호출됩니다.

+0

왜 템플릿이 템플릿을 사용하지 않을 때 클래스가 템플릿을 사용하고 있습니까? 타입 T? – tohidprogram

+2

@tohidprogram 클래스를 사용하는 곳을 공유했는지, 무엇을 위해 공유했는지 쉽게 말할 수 있습니다. – Angew

+0

그것은 기묘하게 반복되는 템플릿 패턴 (CRTP - Google)을 기반으로하는 정책 유형 프레임 워크의 스 니펫처럼 보입니다. * * 특정 멤버 함수는'T'를 사용하지 않지만 다른 멤버 함수는 아마도 사용합니다. – Bathsheba