0

両方がテンプレート化されている、オーバーロードされたメソッドを作成しようとしています。1つは4つの引数を取り、もう1つは5つの引数を取ります。ただし、次の行に沿ってエラーが発生します

Error C2780 ... OutOfPlaceReturn ... : expects 4 arguments - 5 provided.

... A bunch of template parameters ...

See declaration of ' ... ::OutOfPlaceReturn'

4引数のメソッド定義の行を参照する

この場合、5 つの引数でオーバーロードを呼び出そうとしているので、4 つの引数しかとらない関数を呼び出す必要があるとコンパイラが判断する理由がわかりません。

完全なコンテキストは複雑すぎて完全なコード例を示すことはできませんが、これはすべて、、 、 などtypedefを含む多くのローカル sを持つクラス テンプレート内で行われると言えば十分です。これらはすべて、テンプレート引数の型定義のいずれかです。 POD タイプ、またはこれらの POD タイプのいずれかを保持するsamp_typeconst_sampsamp_vecstd::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 データ型についてはかなりうまくいっています。私のコンパイラが標準以下で動作しているかどうかわからない

4

1 に答える 1

1

オーバーロードの解決は、インスタンス化できるテンプレートに対してのみ行われます。これが機能する理由の一部ですSFINAE

あなたの場合、5つの引数のオーバーロードにはあいまいなstrideOut. それはテンプレートパラメータですか?

于 2014-02-10T12:53:07.727 に答える