0

プログラムの何が問題なのかを理解するのに苦労しています。ヘッダー ファイル内のクラス宣言とメンバー関数宣言、1 つの .cpp ファイル内のメンバー関数定義、および main.cpp 内のメイン ドライバー プログラムで構成しました。ここにプログラムを投稿できるように、すべてを ideone の 1 つのファイルにまとめました。

http://ideone.com/PPZMuJ

ideone に表示されるエラーは、ビルド時に IDE が表示するエラーです。誰かが私が間違っていることを指摘できますか?

エラーは次のとおりです。

prog.cpp: In instantiation of ‘IntDLLNode<int>’:
prog.cpp:56:   instantiated from ‘void IntDLList<T>::addToDLLHead(const T&) [with T = int]’
prog.cpp:215:   instantiated from here
prog.cpp:8: error: template argument required for ‘struct IntDLList’

Line 56: head = new IntDLLNode<T>(el,head,NULL);
Line 215: dll.addToDLLHead(numero);
Line 8: class IntDLLNode    {

try/catch 句は無視してかまいません。その部分の作業はまだ完了していません。現在のエラーを回避しようとしているだけです。

4

1 に答える 1

0

問題は、フレンド宣言にあります。

template <class T>
class IntDLLNode    {
  friend class IntDLList;
  // rest of IntDLLNode here
};

ここでは、非テンプレートclass IntDLListをフレンドとして宣言します。後で、同じ名前のテンプレートクラスを宣言します。しかし、思ったより友達にはなりませんIntDLLNode

これを修正するには、フレンド クラスがテンプレートであることを指定します。

template <class U> class IntDLList;

template <class T>
class IntDLLNode    {
  friend class IntDLList<T>;
  // rest of IntDLLNode here
};
于 2012-12-10T20:50:26.743 に答える