can anyone explain why I need to put record* in the map section? Also is this the best way of storing the base class pointers within the map? As I intend to create a database where I can search specific classes by using their id numbers (e.g ash=1, ru=2 , jim=3).
Also for my database search it returns the addresss of mappyiter->second. I was expecting to get the class jim. Ideally i would like to have some sort of mappyiter->print() (i.e jim->print()) but i cant get this to happen.... any ideas??
note// record is an abstract bass class, derived classses from this are physics, fashionm and civileng.
Thanks to anyone who wishes to give me some advice!
[code snippet removed, due to privacy concerns, 2013/04/08]
You declare a map like map<key_type, value_type>. You want it to store record pointers, so value_type is record*. What else could you expect?
As for the method, it is fine, unless you know that all integers from is some range will each represent a record in which case a vector would be better.
Well, the thing that mappyiter points to is not a record*, but an std::pair that stores both the key and the value. So you have to use mappyiter->second->print().
Well, it seems to me that your code was cout << mappyiter->second->print(); where print is declared as virtualvoid print();. print returns a void and you try to feed that void to cout. I assume that print does the "cout << " thing itself, so just call it in another statement. If you really want to use it with <<, make it return a string.