나는 오버로드 된 메서드를 만들려고합니다. 두 메서드 모두 템플릿 처리됩니다. 하나는 4 개 인수를, 나는이 경우 4 인수 메소드 정의함수 템플릿을 다른 함수 템플릿으로 오버로드하는 것이 맞습니까?
의 라인을 참조
Error C2780 ... OutOfPlaceReturn ... : expects 4 arguments - 5 provided.
... A bunch of template parameters ...
See declaration of ' ... ::OutOfPlaceReturn'
의 라인을 따라 오류가 발생하지만 하나 5. 소요 i를 호출하기 위해 노력하고있어 5 인자로 오버로드되므로 컴파일러가 왜 4 인자 만 취하는 함수를 호출하기를 원하는지 이해하지 못한다.
전체 문맥은 전체 코드 예제를 제공하지만,이 모든 등 samp_type
, const_samp
, samp_vec
,이 등 지역 typedef
의 많은,이 클래스 템플릿의 내부에서 일어나는 말을 충분 너무 복잡 포드 유형을 보유하고 템플릿 인수, 또는 이러한 POD 유형 중 하나의 std::array
의 모든 중 형식 정의 템플릿 함수를 호출 할 때
typedef int_fast16_t fast_int;
typedef typename std::add_const<fast_int>::type const_fast_int;
typedef samp_type (*func_type)(const_samp, const_samp);
template<func_type operation, const_fast_int strideA, const_fast_int strideB, const_fast_int strideOut>
static inline samp_vec OutOfPlaceReturn(const std::array<samp_type, strideA * vectorLen> &a,
const_fast_int strideA,
const std::array<samp_type, strideB * vectorLen> &b,
const_fast_int strideB,
const_fast_int strideOut)
{
std::array<samp_type, vectorLen * strideOut> output;
for(fast_int i = 0; i < vectorLen; ++i)
output[i * strideOut] = operation(a[i * strideA], b[i * strideB]);
return output;
}
template<func_type operation, const_fast_int strideA, const_fast_int strideOut>
static inline samp_vec OutOfPlaceReturn(const std::array<samp_type, strideA * vectorLen> &a,
const_fast_int strideA,
const_samp_ref b,
const_fast_int strideOut)
{
std::array<samp_type, vectorLen * strideOut> output;
for(fast_int i = 0; i < vectorLen; ++i)
output[i * strideOut] = operation(a[i * strideA], b);
return output;
}
것은 내가 제대로 이해한다면, 당신은 템플릿을 제공 할 필요가 없습니다 수 있습니다 컴파일러가 함수 인수를 통해 추론 할 수있는 매개 변수는 다음과 같습니다.
static samp_vec subtract(const_vec_ref a, const_fast_int strideA, const_vec_ref b, const_fast_int strideB, const_fast_int strideOut)
{ return OutOfPlaceReturn<MathClass::subtract>(a, strideA, b, strideB, strideOut); }
그래서 이러한 템플릿 메서드를 호출하는 방식에 문제가 있습니까? 오버로드를 해결하기 위해 컴파일러가 기대하는 방식에 문제가 있습니까? 내가 VS2010를 사용하고
편집. 지금까지는 템플릿과 C++ 11 데이터 유형이 꽤 좋았습니다. 내 컴파일러가 하위 파일로 작동하는지 확실하지 않음
오류를 설명한다고 생각하지 마십시오. 그러나 템플릿 매개 변수'strideA'와 함수 매개 변수'strideA'를 갖는 것은 좋지 않습니다. 아마도 함수 매개 변수를 버리고 정의 내에서 템플릿 매개 변수를 사용할 수 있습니다. – aschepler
왜'static'입니까? .. – Potatoswatter
strideA, strideB 및 strideOut을 함수 인수에서 제거하려고했습니다. 컴파일러는 여전히 이번에는 '템플릿 인수가 너무 많습니다.'라고 조금씩 다르게 불평합니다. 이것은 나에게 근본적으로 같은 문제로 보인다. 컴파일러는 어떤 템플릿 방법을 의미하는지 알 수 없다. – xaviersjs