Template inheritance
Hello,
Is it possible to use a user defined Template or from STL as a base class? I'm trying to inherit list template to a class i build.. Alaa G |
Yes you can, but are you sure that is what you want to do? Most of the time a class will have an association with a template classes rather than a specialisation.
That is you include the list as a member variable rather than create a specialisation of it. graeme. |
The thing is that i have many objects that will need a list and its methods. The object will have only other two functions, so that's why i thought about inheriting. Is it a bad idea to inherit a template? and how would you do it.
I have another question, do you know about dictionary object? Is there anything for C/C++, or do i have implement mine? Thanks, Alaa G |
In C++ the dictionary is implemented in the map or multimap template classes
|
It's hard to give you an explanation on how "I would do it" since I don't really know what you want to do.
But say I have a class called student and I want to be able to hold lists of marks and modules enrolled in, then I would make listMark and listModule member variables of the student class. These could be lists of other classes, such as list<mark> and list<module> and I will probably have a class called cohort that contains a list of students. There is a simple rule when deciding if it should be inheritance or not. When you describe the situation would you use the phrase "is a" (inheritance) or the phrase "has a" (association)... A student is a mark ... ? No A student has a mark ... Yes. graeme. |
The reason that I want to do is that I have an Object that act like a map but with more functions. I got it to work and this how:
template <class Key, class Item> class fooMap: public Foo, public map<class Key, class Item> { public: void foo1(); .... }; I have a question, Do you know the difference between "template<class T>" and "template<typename T>"? Alaa |
Quote:
|
thanks for ur help
|
All times are GMT -5. The time now is 12:24 AM. |