テンプレート関数を記述しようとすると、次のエラーが発生し続けます。
main.cpp|17|error: no matching function for call to ‘dotproduct(vector<float, 3u>&, vector<float, 3u>&)’|
エラーを検索したところ、パラメーターが float または double の場合に型以外のテンプレート パラメーターが問題になる可能性がある他のケースがいくつか見つかりました。size_t
行列とベクトルのサイズを決定するために、タイプのないテンプレート パラメータを使用しています。
私は次のクラスを持っています:
マトリックス:
template<class element_t, size_t rows, size_t columns>
class matrix
{
private:
element_t elements_[rows*columns];
// ...
};
ベクター:
template<class element_t, size_t size>
class vector
: public matrix<element_t, size, 1>
{
//...
};
私の機能:
template<class vector_t>
typename vector_t::element_t dotproduct(const vector_t &vector0, const vector_t &vector1)
{
typename vector_t::element_t result_(0);
for(size_t index_ = 0; index_ < vector_t::rows * vector_t::colums; ++index_){
result_ += vector0[index_] * vector1[index_];
}
return result_;
}
から呼び出されます:
int main(int count, char *arguments[])
{
typedef vector<float, 3> vec3;
vec3 a = {1.0f, 2.0f, 3.0f}, b = {3.0f, 2.0f, 1.0f};
std::cout << dotproduct(a, b) << std::endl;
std::cin.get();
}
gcc バージョン 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)