linked of objects

Posted on 2004-04-09
Last Modified: 2012-05-04
how to form a linked list of objects without using structures in the declaration of class. So a class object should point to an other object of the same class.
class temp
    int input;
   temp *next;
Question by:rmvprasad
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Author Comment

ID: 10795793
I dont want to use templates. Thank you.
LVL 10

Expert Comment

ID: 10795817
class Data {
          int myData ;
           Data *next ;
      public :
           Data ( int data = -1 , Data *link = NULL ) : myData ( data ), next ( link ) {}
} ;

class List {
        Data *list ;
    public :
        List () : list ( NULL ) {} ;
       void AddElementToList ( int dataElementToAdd ) ;
       void DisplayList () ;                
} ;

 In     void AddElementToList ( int dataElementToAdd )
You should implement adding a new element by using Data Constructor



Author Comment

ID: 10795848
could you please gibe an sample code that too "You should implement adding a new element by using Data Constructor"
LVL 10

Accepted Solution

Sys_Prog earned 30 total points
ID: 10795900
AddElementToList ( int dataElementToAdd )  {

       Data *newNode = Data ( dataElementToAdd, NULL ) ;

       if ( list == NULL ) {
              list = newNode ;
      else {
            while ( temp -> next != NULL ) {  
                  temp = temp -> next ;
            temp -> next = newNode ;


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question