How to allow your data structure to take in objects of any class - C++ -


How can I do this? As you know in Java, you can use an array list and by the time you are retrieving the object, it will take down any object.

Even better, you can specify that the class of objects that will be done by ArrayList ...

New ArrayList ()

I have implemented a linked list data structure in C ++ and I want to know how I can allow it to ...

Moment, I'm just using ...

typedef whateverObject ItemType

The start of my header file for my linked list In the implementation of the list of "Type Type" links in and then. So every time I want to change this type, eg. Instead of using the list to store stars, I want to store an integer, I have to change the typfix in the header of my linked list, but I want to be able to use it for any object .. .

How ?!

Thank you.

The templates are your answers question.

Define your linked list as follows:

  template & lt; Typename itemtype & gt; Class Array List {// What does not change inside your class definition // Include your method definitions here and you will be fine;);  

is the type to use if ArrayList & lt; Whatever the object & gt; .


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -