2012-03-02 21 views
1

私はMultiListADTを作成しようとして、リストを印刷するコードの作成に問題があります。私はあるクラスの機能を他のクラスの友達にしようとしているので、私はリストを印刷する方法を作り出すことができます。しかし、仕事に友人の機能を取得することができません。私はコードの一部を含めるつもりだから時間がかかりません。エラーはC2039です。 'PrintList'は 'MultiListADT'のメンバーではありません。私はこの仕事をどのようにすることができますか?友人を使用しようとしたときにエラーが発生しました

MultiListADT.h

#include <iostream> 
#include <fstream> 
#include "NodeADT.h" 
#include <string> 

using namespace std; 



template <class TYPE,int threads> 
class MultiListADT 
{ 
public: 
/** Constructor **/ 
MultiListADT(); 

/** Destructor **/ 
~MultiListADT(); 

/** Declare accessors (observers) **/ 
void ResetListForward(int=0); 
void ResetListBackward(int=0); 
bool IsEmpty(int=0); 
int LengthIs(int=0); 
bool Search(TYPE, bool=true,int=0); 
void GetNextItem(TYPE &,int i=0); 
void GetPreviousItem(TYPE &,int=0); 
int GetInfo(int=0); 
int findCountry(TYPE,int=0); 
int findContinent(TYPE,int=0); 
int findYear(TYPE,int=0); 
friend void PrintList(MultiListADT<string,100>&,int=0); 

/** Declare mutators (transformers) **/ 
void MakeEmpty(); 
void AddToFront(TYPE,int=0); 
void AddToRear(TYPE,int=0); 
void InsertInOrder(TYPE,int=0); 
void Delete(TYPE); 
void Sort(); 



private: 
NodeADT<TYPE,threads>* head[threads]; 
NodeADT<TYPE,threads>* tail[threads]; 
int length; 
string indices[threads]; 
NodeADT<TYPE,threads>* currentNode[threads]; 
}; 

template <class TYPE, int threads> 
void MultiListADT<string,100>::PrintList(MultiListADT<string,100> &theList,int i) 
{ 
    //code for reading out list 
} 

NodeADT.h

#include <iostream> 
#include <fstream> 
#include <string> 

using namespace std; 

const int null = 0; 

template<class TYPE, int threads> 
class MultiListADT; 

template <class TYPE, int threads> 
class NodeADT 
{ 
public: 
NodeADT(); 
NodeADT(TYPE); 
~NodeADT(); 
TYPE getInfo(); 
NodeADT<TYPE, threads>* getPrevious(int=0); 
NodeADT<TYPE, threads>* getNext(int=0); 
void setNext(NodeADT<TYPE, threads>*,int=0); 
void setPrevious(NodeADT<TYPE, threads>*,int=0); 
bool Search(TYPE, bool=true,int=0); 
void AddToFront(TYPE item, int=0); 
void AddToRear(TYPE item,int=0); 
void InsertInOrder(TYPE, int=0); 
bool Delete(TYPE,int=0); 
int findCountry(TYPE,int=0); 
int findContinent(TYPE,int=0); 
int findYear(TYPE,int=0); 
bool Comparelist(TYPE,TYPE,int=0); 
friend void PrintList(MultiListADT<TYPE,threads>&,int=0); 
private: 
TYPE info; 
NodeADT<TYPE, threads>* prev[threads]; 
NodeADT<TYPE, threads>* next[threads]; 
}; 

答えて

1

まず、がprintlist部材または非会員であることが意図されていますか?あなたは、この持っている:

friend void PrintList(MultiListADT<string,100>&,int=0); 

を...まだあなたがメソッドのようにそれを定義しようとしている:これは読まなければならないこと

template <class TYPE, int threads> 
void MultiListADT<string,100>::PrintList(MultiListADT<string,100> &theList,int i) 
{ 
    //code for reading out list 
} 

注:

template <class TYPE, int threads> 
void MultiListADT<TYPE,threads>::PrintList(MultiListADT<TYPE,threads> &theList,int i) 
{ 
    //code for reading out list 
} 

それは方法だ場合MultiListADTでは、それを友人として宣言する必要はありません。それを通常の方法として定義してください。 NodeADTからそのメソッドにアクセスする場合は、そのメソッドがプライベートであれば、MultiListADTクラスをフレンドにすることができます。しかし、それはあなたがあなたがまったく友達を必要としない場合にはそれを公開させようとしているように私に見えます。

最後に、アドバイスとして、できるだけ友人を避ける方法を見つけることをお勧めします。デザインについて懸命に考えて、std :: vector、std :: listなどの標準コンテナを見てください。これにより、これらの集約の内部にアクセスする他の種類の友人がなくても内容を印刷できます。どうやって?これらのコレクションはイテレータを提供します。これはあなたのリストデザインに欠けているような非常に重要な概念です。

イテレータを提供することで、実際に内部的なものにアクセスしようとすることなく、リストを使って想像できるものを実装することができます。

+0

友人を使う理由は、私の教授が特定の状況でそれを使用するように言われていて、それを他の方法で行う方法を本当に考えることができないということです。 – Soul3lade

+0

さて、私はそれを試してみましたが、今では方法を認識していますが、「次へ」と「情報」にアクセスできないというエラーがたくさんあるので、友人の特典が得られないと思います。 – Soul3lade

+0

申し訳ありません私はMultiListADTの中でメソッドを使用しています。 – Soul3lade

関連する問題