Solved i am using dev c++ id am geeting an error how can i solve it

January 22, 2015 at 18:53:33
Specs: Windows 7
Iam geeting an error like "exptect qualified id before public " in line 24, please any body help me. and the code is

using namespace std;
struct node
int data;
struct node *next;
class Reverse
struct node *head;
void gen(struct node **head);
void print(struct node *head);
struct node *head=NULL;
Reverse p1;
public void Reverse::gen(struct node **head)
struct node *temp;
int i,num;
cout<<"enter number of nodes to be generated";
temp=new(struct node);
if(**head == NULL)

public void Reverse::print(struct node *head)
if(*head == NULL)

See More: i am using dev c++ id am geeting an error how can i solve it

Report •

January 23, 2015 at 02:23:26
✔ Best Answer
There are multiple errors in your program.

1. You don't specify a return type for "main()".

2. You include the keyword "public" in front of the definitions of your class methods - it is only used in their declaration.

3. Most seriously, you don't seem to understand the "*" operator. This means that you are, for example, trying to compare a "node" to NULL. As you haven't defined a comparison operator for nodes this fails. When a variable "temp" is a pointer to a node (struct node *temp), temp is a pointer (and so can be compared to NULL) whereas *temp is a struct node (and so cannot be compared to NULL).

The first two errors are trivial syntax errors. The third error is serious; you need to review your understanding of pointers.

Report •
Related Solutions

Ask Question