コーディングする必要があるテンプレートのスケルトンが与えられました。テンプレートを実際に扱ったことはありません。このテンプレートの奇妙な点は、テンプレート自体内にクラスをコーディングする必要があることです。クラス関数だけでなく、まったく新しいクラスです。テンプレート用のコードは次のとおりです (開始するために、いくつかのメソッド内に数行のコードを挿入しましたが、それらは私の問題にとって重要ではありません)。
含む
template<class K, class V> class HMap
{
private:
// insert instance variables
// insert constants (if any)
public:
class MapEntry
{
private:
K key;
V value;
public:
/**
* Creates a MapEntry.
*
* @param akey the key
* @param avalue the value
*/
MapEntry(K akey, V avalue)
{
key = akey;
value = avalue;
}
/**
* Returns the key for this entry.
*
* @return the key for this entry
*/
K getKey()
{
return key;
}
/**
* Returns the value for this entry.
*
* @return the value for this entry
*/
V getValue()
{
return value;
}
/**
* Sets the value for this entry.
*
* @param newValue
* @return the previous value for this entry
*/
V setValue(V newValue)
{
V oldval;
oldval = value;
value = newvalue;
return oldval;
}
};
HMap テンプレート タイプのオブジェクトを作成する場合、その中で MapEntry クラスをどのように使用しますか? 私はテンプレートにまったく慣れていないので、どこから始めればよいかわかりません。ありがとうございました。