私はC++でテンプレートを使うのがかなり新しいです。 以下は私が使用しようとしているコードです。私はそれのためのオブジェクトを作成し、それで定義されたメソッドを使用する方法として把握できないので、私は次のコードを使用することができません。オブジェクトを作成できず、テンプレートクラスのメソッドを使用することができません
template <typename UInt> class nCr {
public:
typedef UInt result_type;
typedef UInt first_argument_type;
typedef UInt second_argument_type;
result_type operator()(first_argument_type n, second_argument_type k) {
if (n_ != n) {
n_ = n;
B_.resize(n);
} // if n
return B_[k];
} // operator()
private:
int n_ = -1;
std::vector<result_type> B_;
};
そして、どのように私は、オブジェクトを作成していますが次のとおりです。このため
#include <iostream>
#include "math.hpp" // WHere the above class nCr is defined
int main() {
int n =4;
nCr x(4,2);
return 0;
}
私は
error: use of class template 'jaz::Binom' requires template arguments
nCr x(4,2);
^
./include/math.hpp:68:34: note: template is declared here
template <typename UInt> class nCr {
~~~~~~~~~~~~~~~~~~~~~~~~ ^
として任意の提案を、エラーを作成していますか?