(회원이 아닌) 함수에서 부분 템플릿 전문화를 사용하려고하고 있는데 구문에 신경 써야합니다. 다른 부분 템플릿 전문화 문제에 대해 StackOverflow를 검색했지만 클래스 또는 멤버 함수 템플릿의 부분적 특수화를 다루고 있습니다. 시작 지점에 대한 (비 멤버) 함수에 부분 템플릿 특수화를 사용할 수 있습니까?
, 내가 가진 :template <>
Grayscale ConvertPixel<RGBA, Grayscale>(RGBA source) {
return Grayscale(IntensityFromRGB(source.r, source.g, source.b));
}
내가 생각할 수있을 것이다 :
struct RGBA {
RGBA(uint8 red, uint8 green, uint8 blue, uint8 alpha = 255) :
r(red), g(green), b(blue), a(alpha)
{}
uint8 r, g, b, a;
};
struct Grayscale {
Grayscale(uint8 intensity) : value(intensity) {}
uint8 value;
};
inline uint8 IntensityFromRGB(uint8 r, uint8 g, uint8 b) {
return static_cast<uint8>(0.30*r + 0.59*g + 0.11*b);
}
// Generic pixel conversion. Must specialize this template for specific
// conversions.
template <typename InType, typename OutType>
OutType ConvertPixel(InType source);
내가 이런 그레이 스케일 변환 기능에 RGBA를 만들기 위해 ConvertPixel의 전체 전문화를 할 수 빨강, 녹색 및 파랑을 제공하는 더 많은 픽셀 유형을 지원하지만 다른 형식 일 수도 있습니다. 따라서 내가하고 싶은 것은 Grayscale
을 OutType
에 지정하고 부분적으로는 InType
을 허용합니다. 나는 다음과 같은 다양한 접근법을 시도했다 :
template <typename InType>
Grayscale ConvertPixel<InType, Grayscale>(InType source) {
return Grayscale(IntensityFromRGB(source.r, source.g, source.b));
}
그러나 (Microsoft VS 2008 C++) 컴파일러는이를 거부한다.
내가 시도하고있는 것은 무엇입니까? 그렇다면 올바른 구문은 무엇입니까?
합니다. 오버로드 사용 – KeatsPeeks