我编译了以下代码:
typedef unsigned char uint8;
template <uint8 N> inline uint8 g(uint8 x) { return x > N ? 1 : 0; }
template <size_t stride, size_t boxsize, class T, class F>
inline void boxfilt(size_t width, size_t size, T * inout, const F & f) {
}
template <class T> inline T self(const T & x) { return x; }
template <size_t stride, size_t boxsize, class T>
inline void boxfilt(size_t width, size_t size, T * inout) {
return boxfilt<stride, boxsize>(width, size, inout, self<T>);
}
int main(int argc, char* argv[])
{
uint8 *out = NULL;
boxfilt<3,4>(10,29,out,g<4>);
return 0;
}
在g ++编译器中,它工作正常。当我尝试在Visual Studio 2008编译器中编译相同的代码时,它显示以下错误:
Error 1 error C2780: 'void boxfilt(size_t,size_t,T *)' : expects 3 arguments - 4 provided g:\testfjx\test\test.cpp
Error 2 error C2784: 'void boxfilt(size_t,size_t,T *,const F &)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type' g:\testfjx\test\test.cpp
Error 3 error C2784: 'void boxfilt(size_t,size_t,T *,const F &)' : could not deduce template argument for 'T *' from 'uint8 *' g:\testfjx\test\test.cpp
如何解决此问题?
答案 0 :(得分:1)
没关系,在Visual C ++ 2008中也是如此。
如果VC ++ 2008和G ++ 4.7.2都接受代码而VC ++ 2005没有接受代码,那么VC ++ 2005可能有bug,也许它没有完全实现C ++规范。