を使用しているとき、私は、キーワード「型名」を使用する必要があります。..私は小さなプロジェクトで最近取り組んできた、と私は何かを把握することができませんでしテンプレート
私はその.hファイルを与えられてきましたtypenameテンプレートを使用してクラスを含んでいました。そのクラスの中にプライベートクラスがありました。私はクラスの関数を定義したいときに問題が
を「何か」を発生し
template <typename T>
class Something
{
public:
Something();
~Something();
Node* Function1(int index);
int Index(const T& id);
private:
class Node()
{
public:
T id;
//Imagine the rest for the Node
};
};
ここで(.inlファイルに)私はそれをやっていた方法です
template<typename T>
Node* Something::Function1(int index) //Is the return type well written?
{
// returns the node at the specified index
}
template<typename T>
int Something::Index(const T& id) //Is the parameter type well specified?
{
// returns the index of the node with the specified id
}
ので盗聴その部分は定義部分にありました...戻り値の型(この場合はNode *)がtypenameテンプレート(これはtypename Node*
)を使用することをコンパイラに伝えなければなりませんか?パラメータはどうですか? typename const Node&
?
基本的に、関数/パラメータがテンプレートを使用するかどうかを指定する必要があるのはいつですか?
お時間をいただきありがとうございます。
あなたの質問にsinppetsを投稿してください! – mmmmmmmm
スニペットとのリンクを投稿しました。私はスニペットを正しくインデントする方法を理解できませんでした。 – Pacane