Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How is it possible to define the class in terms of itself?

Status
Not open for further replies.

DrDolittle

Full Member level 3
Full Member level 3
Joined
Sep 24, 2004
Messages
162
Helped
5
Reputation
10
Reaction score
1
Trophy points
1,298
Location
Within arm's reach
Activity points
1,443
class intnode
{
public:
int info;
intnode *next; // this is the part i wanted to know
intnode(int i, intnode *in=0)
{
info = i;next = in;
}
};

you can ignore what is in the loop. As the comments denote, that is the part i wanted explanation for. info and next are data members of the class intnode. But how is it possible to define the class in terms of itself. Can somebody explain this ? i would very much appreciate if someone could come up with more examples. Tack!(thanks)

Regards
drdolittle
 

Re: please explain this

this is pointer to intnode, right? not intnode itself. it is not possible to declare a data member of an object to be the same type as the object itself, but it is possible to declare a pointer to an object that has the same type. a type is different from a pointer to that type. an intnode is an intnode, but a pointer to intnode is a variable containing the address of some object that has the type of intnode.

i think this is a linked list. you can find many more examples in books about data structure and algorithm. linked list is usually used in stacks, queues, etc.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top