2010-07-26 6 views
3

내가 멤버 함수 모멘트 (전문하려고 해요) 만 (안 구멍 클래스) :CPP이 같은 템플릿 멤버 함수 전문

실제 전문화 추가 abstractWaveletSpecialization 구조체에서 발생
template<class Derived, class T> 
class AbstractWavelet { 
public: 
    [...] 

    template<bool useCache> 
    const typename T::scalar moment(const int i, const int j) const { 
    return abstractWaveletSpecialization<Derived, T, useCache>::moment(static_cast<const Derived*>(this), i, j); 
    } 
    template<bool useCache> 
    friend const typename T::scalar abstractWaveletSpecialization<Derived, T, useCache>::moment(const Derived* const that, const int i, const int j); 

protected: 
    // returns the jth moment of the ith scaling function 
    template<bool useCache> 
    inline const typename T::scalar momentImpl(const int j, const int i) const { 
    [...] 
    } // momentImpl 
}; 

:

error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘bool’ to binary ‘operator<’ 
012 :
template<class Derived, class T, bool useCache> 
struct abstractWaveletSpecialization { 
    inline static const typename T::scalar moment(const Derived* const that, const int i, const int j) { 
    return that->momentImpl<useCache>(i,j); 
    } 
}; 


template<class Derived, class T> 
struct abstractWaveletSpecialization<Derived, T, true> { 

    typedef const std::pair<const int, const int> momentCacheKey; 
    typedef std::map<momentCacheKey, 
       const typename T::scalar> momentCacheType; 
    static momentCacheType momentCache; 


    inline static const typename T::scalar moment(const Derived* const that, const int i, const int j) { 
    momentCacheKey cacheKey(i,j); 
    typename momentCacheType::iterator idx = momentCache.find(cacheKey); 

    if (idx == momentCache.end()) 
     return that->momentImpl<true>(i, j); // COMPILE ERROR HERE 
    else 
     return momentCache[cacheKey]; 
    } 
}; 

문제는 내가 전문 abstractWaveletSpecialization 구조체에 momentImpl()를 호출 할 수 없다는 것입니다

하지만 컴파일러는 특수화되지 않은 abstractWaveletSpecialization 구조체에서 momentImpl 호출에 대해 불평하지 않습니다.

내 접근법이 C++에서 금지되어 있습니까? 아니면이 방법을 만들 수있는 방법이 있습니까?

+0

[템플릿과 "typename"키워드를 어디에 왜 넣어야합니까?] (http : //stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – ecatmur

답변

2

that->template momentImpl<true>(i, j); 시도해주세요. 컴파일러에게 "이봐 요, 이후의 일은 템플릿 호출입니다"

+0

이 구문은 이상하게 보입니다. 하지만 작품입니다! – Manuel

+0

예, 전혀 이상하지 않습니다. 그러나 그것은 고급 템플릿 C++을 사용할 때입니다 : – Scharron

+1

@Manual : 문제는 A와 B가 템플릿이되는 A-> B B B '중 하나입니다. 그것이 객체라면,'A-> B sbi

관련 문제