"farming"という文字を含むテキストファイルをノードのリンクリストに読み込もうとしています。私はノードの構造を持つNumberListという名前のクラスを作った。ここにヘッダーがあります。ファイルをリンクリストに読み込むクラスのノード構造を持つC++
#ifndef NUMBERLIST
#define NUMBERLIST
#include <iostream>
using namespace std;
class NumberList
{
protected:
//declare a class for the list node
//constructor to initialize nodes of list
struct ListNode
{
char value;
ListNode *next;
// Constructor
ListNode(char value1, ListNode *next1 = NULL)
{
value = value1;
next = next1;
}
};
ListNode *head; //pointer to head of the list
public:
NumberList() { head = NULL; } //constructor
~NumberList(); //destructor
void displayList() const; //print out list
void reverse();
};
#endif
問題が発生している箇所では、テキストファイルをmain()のリンクリストに読み込もうとしています。
#include "Numberlist.h"
#include "ReliableNumberList.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ListNode *letterList = nullptr; //create a linked list
char letter;
//This is where I read the file into the list
//open the file
ifstream letterFile("linkedText.txt");
if (!letterFile)
{
cout << "Error in opening the file of letters.";
exit(1);
}
//read the file into a linked list
while (letterFile >> letter)
{
//create a node to hold this letter
letterList = new ListNode(letter, letterList);
//missing a move to the next node?
}
return 0;
}
この読み取りファイルのサンプルは私の教科書から来たが、構造別のクラスに位置していなかったにその読み:
は、ここで私がメインに持っているものです。私の人生では、ListListクラスのListNode構造体をどのように参照するのか分かりません。 Visual Studioでは、ListNodeとletterListが定義されていないことを示しています。私はNumberListクラスからそれらを適切に参照していないので、そのことを知っています。
ご協力いただければ幸いです。
あなたの問題への迅速な解決策は、この可能性が
ようこそスタックオーバーフロー。 [The Tour](http://stackoverflow.com/tour)を読み、[ヘルプセンター](http://stackoverflow.com/help/asking)の資料を参考にしてください。ここに聞いてください。 –
'ListNode'構造体は外界から'保護されているようです。おそらく、 'NumberList'がchar(内部/保護された)リストに' char'を追加するメソッド( 'push_back(...)')を持つような考え方でした。このように 'NumberList'オブジェクトはノードの作成と破壊を管理し、' main() 'では毎回直接' ListNode'を作成するのではなく、かなり 'list.push_back(letter)'だけ書く必要があります。 – Drop
さらに、 'ListNode'は実際には' NumberList :: ListNode'です。 'ListNode'は' NumberList'の中にあります。 'NumberList'は' NumberList'であるため、完全に修飾する必要はありません。 – user4581301