I've seen a couple similar questions on here, but I can't seem to match any of their problems to my program. Can someone help me identify why it won't let me declare my struct in my .h file?
The error I am getting is ISO forbids declaration of 'post' with no type.
Thanks in advance, I appreciate you having taken a look at my file.
#include <iostream>
4 #include <cstring>
5 #include <cctype>
6 using namespace std;
7
8 // stuct to hold the individual posts
9
10 struct post
11 {
12
13 int rating;
14 char comment[];
15 post * next;
16
17 };
18
19 //class to hold the functions as well as serve as a linked list of topics
20
21 class blog
22 {
23
24 public:
25
26 blog();
27 ~blog();
28 int post(char new_topic[], char new_comment[]);
29 int display(char topic[]);
30 int display_all();
31 int rate(char topic[], char keyword[], int rating);
32 int remove(char topic[], char keyword[]);
33
34 private:
35
36 blog * head;
37 blog * tail;
38 blog * next;
39 char * topic;
40 post * next_post;
41 post * last_post;
42
43 };
You have a name conflict. In class blog
, the name post
refers to two different things. One is struct post
and the other is a member function.
Rename one of them. Using ::post
or struct post
to refer to the struct is another possibility, but it's more confusing to the reader
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.