Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrapper classes and Generic List/Vector

Status
Not open for further replies.

ankursaxena

Programmer
Sep 7, 2001
133
US
Hi!
i was thinking of writting up few wrapper classes for certain primitve data-types, plus some collection classes like vector, link list, stack etc..i wanted to make my vector a generic list, which can hold different objects in each node.
I had thought of using void* but i am not too sure if it will work good, cuz may be u wanna create a list of user objects which intern contain pointer and if u wanna make a good design then the person who allocates memory should be the one deallocating it, so say the main() allocates memory and passes the object to the void* list then if the person deletes it then even the list will lose the pointer inside the object class, hope u under what i am trying to say.

so what i thought was create an "Object" class of my own, which contains nothing else but a classID and then create wrapper classes from there on which are derived from this "Object" class eg.
Object
PrimitiveDataType
Character
Integer
String
Long
FLoat

Collector
Vector
Stack
...
.
.
etc.

and thus in my code i create a vector storing "Object" class pointers and somehow in your vector class you switch and find out which object it is, do an actual data copy, by creating ur own memory for this object and storing it, because all of the classes are derived from "Object" class you can have dynamic bindnig and it should work, i have not been able to write this up yet, but was just thinking about it, i am also not a very experienced programmer, so to make myself one, i wanted to design and gain experience.

if someone does read, it would be greate if some god, experienced programmers can help me, doesnt matter if u tell me that this is crap. it alright,i am still learning.
thanx a lot.

-Ankur
 
Writting the wrapper classes would be a bit of work with little return other that being able to store them in the same array. My question is why would yu want an array that has - {int,float,char,int,int,float} if there is a reason to group this data together than that grouping is better abstracted as a class. for instance say want to do a 2 dimentioal array, like such
vector< vector < obcect > >
and each element of vector is {int,float,char,string} that hold data for a student.... you'd be better making a student class and a vector<students>

I'm not saying you shouldn't, just consider exsactly why you'd want to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top