我正在尝试专门化成员函数moment()(而不是整个类),像这样:
实际的专业化发生在一个额外的abstractWaveletSpecialization结构中:
问题在于我无法在专门的abstractWaveletSpecialization结构中调用momentImpl()函数:
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
};
实际的专业化发生在一个额外的abstractWaveletSpecialization结构中:
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()函数:
error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘bool’ to binary ‘operator<’
但是编译器不会对非特化的abstractWaveletSpecialization结构中momentImpl函数的调用进行投诉。
我的做法在C++中被禁止了吗?还是有其他方法可以让这个工作起来?