Hey, I'm starting to program a linked list application, so I am playing around with creating Nodes to familiarize myself with them. I created a very simple program how I could practice creating a new node and pointing the previous node pointer to the new node, but it won't compile. Here is my code:
myLL.h
main.cppCode:#ifndef HEADER_H #define HEADER_H #include <string> struct Node { std::string nvalue; Node *ptr; } #endif
Error:Code:#include <cstdlib> #include <iostream> #include "myLL.h" 5: int main(int argc, char *argv[]) 6: { 7: Node myNode; 8: myNode.nvalue = "Hello"; 9: 10: system("PAUSE"); 11: return 0; }
I don't see where the compiler is getting the "extraneous int" and why it does not think that main.cpp is not returning an int.Code:6 main.cpp new types may not be defined in a return type 6 main.cpp extraneous `int' ignored 6 main.cpp `main' must return `int' 6 main.cpp return type for `main' changed to `int' Makefile.win [Build Error] [main.o] Error 1
What I am trying to do: each Node structure has a string nvalue and a pointer to a node ptr. The user will be able to input as many strings as he/she wants, and for each new string the program will create a new node, assign nvalue to the string that was just inputted, and update the previous node ptr to point to the new node. Of course, I have not implemented all of this yet.