Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

If you wanted to put int,double into your own container class would you do it?

  1. Sep 29, 2011 #1
    If you wanted to put ints, doubles, strings into your own container class how would you do it?
     
  2. jcsd
  3. Sep 29, 2011 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    It might help if you said which language you are talking about.
     
  4. Sep 29, 2011 #3

    chiro

    User Avatar
    Science Advisor

    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++.
     
  5. Sep 29, 2011 #4
    Sorry, I forgot to mention I am trying to do it in Java
     
  6. Sep 29, 2011 #5

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Then you can use generics. Look into List<A>, ArrayList<T>, Vector<T>, etc.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: If you wanted to put int,double into your own container class would you do it?
  1. How do you compile C? (Replies: 5)

Loading...