#include<iostream>
using namespace std;
class linkedlist
{private:
llink* firstelem;
.....................................
struct llink
{
int elem;
llink* nextelem;
}
......................................//when i take the struct out the class definition , the program
works well.but just like this it doesn't working! i am confused .
...........................................................................
public:
linkedlist(void);
~linkedlist(void);
void AddElement(int elem1);
void DisplayList(void);
};
linkedlist::linkedlist()
{
firstelem=NULL;
}
linkedlist::~linkedlist(void)
{ }
void linkedlist::AddElement(int elem1)
{
llink* newlink=new llink;
newlink->elem=elem1;
newlink->nextelem=firstelem;
firstelem=newlink;
}
void linkedlist::DisplayList()
{ llink* currentelem=firstelem;
while(currentelem!=NULL)
{
cout<<currentelem->elem<<"-";
currentelem=currentelem->nextelem;
}
cout<<"END"<<endl;
}
int main()
{
linkedlist TestList;
TestList.AddElement(5);
TestList.AddElement(54);
TestList.AddElement(3);
TestList.AddElement(25);
TestList.DisplayList();
return 0;
}
wu7jian
0
Newbie Poster
Recommended Answers
Jump to Poststruct llink { int elem; llink* nextelem; } ......................................//when i take the struct out the class definition , the program works well.but just like this it doesn't working! i am confused . ...........................................................................
You have to end a struct with ;
should be
Jump to Posthardly any variable you use is not defined...
also use TABSPACE for formatting CODE... its very hard to read without them.
and why on every function do you have (void) as a variable or variable type?? those are not needed
All 7 Replies
jhdobbins
0
Junior Poster
wu7jian
0
Newbie Poster
jhdobbins
0
Junior Poster
Narue
5,707
Bad Cop
Team Colleague
wu7jian
0
Newbie Poster
Lerner
582
Nearly a Posting Maven
wu7jian
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.