error: "Node" has not been declared

Good evening,
I've been trying to write a linked list code for a while today, where I have two structs, one calling another. I also have a function, but attempting to pass the struct as an argument for the function returns an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;



void push_front(double pop, string name, Node*& n, Node*& t); //Error here for both n and t


	
void push_front (double pop,string name, Node*& n, Node*& t)//Error here as well
{	

	n= new Node;
	n->ctry.population=pop;
	n->ctry.name=name;
	t->next=n;
	t=t->next;


}


int main()
{


 	struct Country {
  	 string  name;
   	 double  population;
  	 };

  	struct Node {
  	 Country ctry;
  	 Node *  next;
 	 };
	 


        Node * world;
        Node* n;
	Node* t;
	t=n;
/*blah;
blah;
blah;
*/



	
return 0;
}


The error reads as the title, saying that Node was not declared,
What gives?
(This is beginner level stuff, I am trying to make a simple linked list with data read from a file, but I did not reach that part of the code yet)

Any help is appreciated
You currently have the definition of the struct Node located after your function definition that expects a Node.

Move the definition of Node to before the function prototype.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

struct Country {
    string  name;
    double  population;
};
struct Node {
    Country ctry;
    Node *  next;
};
	 

void push_front(double pop, string name, Node*& n, Node*& t); //Error here for both n and t


	
void push_front (double pop,string name, Node*& n, Node*& t)//Error here as well
{
    // ...
Last edited on
And to think I've been struggling for the past few hours for that :)...
Thanks for your help!
Topic archived. No new replies allowed.