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

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct node
{
int data;
struct node *next;
};
class Reverse
{
public:
struct node *head;
void gen(struct node **head);
void print(struct node *head);
};
main()
{
struct node *head=NULL;
Reverse p1;
p1.gen(&head);
p1.print(head);
};
public void Reverse::gen(struct node **head)
{
struct node *temp;
int i,num;
cout<<"enter number of nodes to be generated";
cin>>num;
for(i=num;i>0;i--)
{
temp=new(struct node);
temp->data=i;
if(**head == NULL)
{
**head->next=NULL;

}
else
{
temp->next=**head;
**head=temp;
}
}
}
public void Reverse::print(struct node *head)
{
if(*head == NULL)
{
return;
}
cout<<"*head->data";
print(head->data);
}


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

Report •


#1
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