View Full Version : If you wanted to put int,double.. into your own container class would you do it?
SpiffyEh
Sep29-11, 01:24 AM
If you wanted to put ints, doubles, strings into your own container class how would you do it?
CompuChip
Sep29-11, 02:25 AM
It might help if you said which language you are talking about.
If you wanted to put ints, doubles, strings into your own container class how would you do it?
Aside from CompuChip's suggestion, you also need to define the size and the orientation of your "words".
My suggestion to you is if you are doing your development in something C/C++, you should typedef your doubles, ints, and strings so that they are always in the same format regardless of the platform.
Typically what happens is that an int is platform dependent. On a 32-bit platform is 32 bits and on a 64-bit platform it is 64-bits. The best way to get around this is to define something like INT32 which is guaranteed to 32 bits regardless of what platform you execute the code on.
Also with strings, are they fixed length or are they allocated on the heap? If they are allocated on the heap, then your string data will not be able to stored in your structure as a TYPE or struct definition. One way around this is to use a large flat area of memory that is the maximum size of a string. Languages like BASIC can do this, and it's very easy to do this with a struct definition in C/C++.
SpiffyEh
Sep29-11, 10:48 AM
Sorry, I forgot to mention I am trying to do it in Java
CompuChip
Sep29-11, 11:39 AM
Then you can use generics. Look into List<A>, ArrayList<T>, Vector<T>, etc.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.