I'm trying to make a program to allow me to enter information(mainly books) in to a sort of library. I read that <list> is an easy way to add things and sort them.

Also by use a hierarchy I can use my base class and just add on to each different type of item i wish to add. Is there a sample code or tutorial to help me with this?

Recommended Answers

All 6 Replies

What types of items do you want to be derivities of a base class? Such as books, movies, newspapers, broadway plays, etc. ?

<list> is similar to normal linked lists. <vector> is like an array. Which to use depends on what you want to do with them. And both are far superior to the C counterparts (linked lists and array).

i plan on doing

class Data
{
Title
Author
Publisher

}

class video :: class Data
{
Length
Genre
}

class video:: class magazine
{
Edition
Editor
}

as for the <list>

I plan on storing each of the books, movies and mags

I read up on it and its easier to use by using push. instead of having to set the space to null increasing it and what not

you might want to use a vector

vector<Data*> theList;
magazine* n = new magazine;
theList.push_back(n);
video* v = new video;
theList.push_back(v);

One problem in the above is you need some method to distinguish the class types when extracting them from the vector. Is theList[0] of class magazine or video? You might want an indicator (integer) in the base class.

theList[0] = data(a book)
theList[1] = video
theList[2] = mag

Member Avatar for jencas
class video:: class magazine

should be

class magazine : public data
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.