2016-11-10 6 views
-1

リンクリストを作成してtxtファイルをダウンロードし、リンクリストを使用してファイルを1行ずつ処理しようとしています。ダウンロードされたリンクされたリストを操作するとき、テキストエディタなどの操作が実行されます。 しかし、私はいくつかの問題に遭遇しています。 "ノード(文字列値)"セクションには、引数のない元のNode()宣言が渡されても何か問題があるようです。私はそれが何であるかを理解することができません。C++リンクリスト

Node.h

class Node 
{ 
public: 
    Node(); 
    Node(string value); 
    void setNext(Node *nextNode); // Allows the user to set where the "next" pointer of a node points 

    friend class LinkedList; 
private: 
    string data; // Data box 
    Node* next; // Pointer box 
}; 

Node.cpp

# include <string> 
# include "Node.h" 

using namespace std; 

Node::Node() 
{ 
    data = ""; 
    next = NULL; 
} 

Node::Node(string value) 
{ 
    data = value; 
    next = NULL; 
} 

void Node::setNext(Node *nextNode) // Allows the user to set where the "next" pointer of a node points 
{ 
    this->next = nextNode; 
} 
+2

"いくつかの問題" と "何か間違ったこと" よりも具体的にしてください。それはコンパイルされませんか?それはクラッシュしますか?それはあなたの端末の上に "0x3434"を印刷しますか?それは警察に電話し、あなたが行方不明になったと報告しますか? – molbdnilo

+0

@molbdnilo、それはただのランダムな質問を投稿することがありますか? ;) – SergeyA

+0

次のエラーが表示されます。 型指定子がない - 想定されています。行:17 'data':不明なオーバーライド指定子行:17 – Blake

答えて

2

あなた#include <string>それはあなたがあなたの方法でstd::stringタイプを使用していているので、あなたのヘッダファイルにする必要があります。

それは名前空間を使用して文字列型を宣言し、(詳細はthis answerを参照してください)ヘッダファイルでusing namespaceを追加することは推奨されませんので:変更あなたのstring value

std::string valueへのあなたのファイルは次のようになります(テストをコンパイルしましたGCCで行う)

また、あなたは、あなたのヘッダファイルに

例が含まガードを置く必要があります。

// some_header_file.h 
#ifndef SOME_HEADER_FILE_H 
#define SOME_HEADER_FILE_H 
// your code 
#endif 
0を

Node.h

#include <string> 

class Node 
{ 
public: 
    Node(); 
    Node(std::string value); 
    void setNext(Node *nextNode); // Allows the user to set where the "next" pointer of a node points 

    friend class LinkedList; 
private: 
    std::string data; // Data box 
    Node* next; // Pointer box 
}; 

Node.cpp

#include "Node.h" 
#include <cstddef> // For NULL 

Node::Node() 
{ 
    data = ""; 
    next = NULL; 
} 

Node::Node(std::string value) 
{ 
    data = value; 
    next = NULL; 
} 

void Node::setNext(Node *nextNode) // Allows the user to set where the "next" pointer of a node points 
{ 
    this->next = nextNode; 
} 
+0

[あるいは、ガードをインクルードする代わりに '#pragma once'](http:// stackoverflow。com/questions/1143936/pragma-once-vs-include-guards) –

+0

これは、stringがstdライブラリのコンポーネントではないことを示唆しています。 また、既に私は を持っています。#ifndef NODE_H #define NODE_H と#endif ..彼らは私が求めているものではありません。 – Blake

+0

***文字列がstdライブラリのコンポーネントではないことを示唆しています。***ヘッダーとcppファイルで 'string'を' std :: string'に置き換えましたか? – drescherjm

関連する問題