C++ Linked List -
i trying create linked list download txt file , use linked list handle file line line. when handling downloaded linked list operations performed on such text editor would. encountering problems however. seems "node(string value)" section of code has wrong though original node() declaration no arguments passes. unable figure out quite is.
node.h
class node { public: node(); node(string value); void setnext(node *nextnode); // allows user set "next" pointer of 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 user set "next" pointer of node points { this->next = nextnode; }
your #include <string>
should in header file since using std::string
type methods.
since not recommended add using namespace
in header files (see this answer more info), declare string types namespace : change string value
std::string value
your files (compile test done gcc)
also should put include guard in header file
example:
// some_header_file.h #ifndef some_header_file_h #define some_header_file_h // code #endif
node.h
#include <string> class node { public: node(); node(std::string value); void setnext(node *nextnode); // allows user set "next" pointer of node points friend class linkedlist; private: std::string data; // data box node* next; // pointer box };
node.cpp
#include "node.h" #include <cstddef> // null node::node() { data = ""; next = null; } node::node(std::string value) { data = value; next = null; } void node::setnext(node *nextnode) // allows user set "next" pointer of node points { this->next = nextnode; }
Comments
Post a Comment