I want to create a generic list of objects.
I could specify the list type ie
typedef Plorg Item;
Instead I want it to be generic (the type of list) and based on an object sent to the function create, which would create a list of the object refrenced. One alternative is too create a constructor of list type that resolves to a list of type any object passed to it.
How do I resolve Any to the type of object passed either in the function create or a constructor of the List class.
Code:// List of customers prblm 3 pg 417 c++ primer plus #ifndef _ListH_H_ #define _ListH_H_ template <typename Any> // typename any void create(Any &a, Any &b); typedef Any Item; // is this valid? class List { private: enum {MAX=10}; Item items[MAX]; int index; public: List(); bool isempty() const; bool isfull() const; // add returns false if List is full, else true bool add(const Item &item); // add item to List // edit list function pointer void List::edlist(void (*pf)(Item &)) }; class Plorg { private: char name[19]; // ci--contentment index int ci; public: Plorg(); void eat(); void report(); }; #endif



LinkBack URL
About LinkBacks


