CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: how to autogenerate array?

  1. #1
    Join Date
    Dec 2005
    Posts
    71

    how to autogenerate array?

    let say, in my program i want to create an array for matrices. user can choose any name for the matrices. so, user can create as many matrices as they want. how can i make an autogenerate array so that it won't just limit to 2 - 3 matrices only.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,768

    Re: how to autogenerate array?

    Use a vector of matrices? Or maybe a map, if the name of a matrix is particularly significant here.

  3. #3
    Join Date
    Dec 2005
    Posts
    71

    Re: how to autogenerate array?

    can u give me some example?

  4. #4
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: how to autogenerate array?

    Quote Originally Posted by magix24
    let say, in my program i want to create an array for matrices. user can choose any name for the matrices. so, user can create as many matrices as they want. how can i make an autogenerate array so that it won't just limit to 2 - 3 matrices only.
    If you want to use an array, you can only make it that big that the probability one needs to create so many matrices is very low.
    Or you have to dynamically create a new bigger array everytime a new matrix is created, copy the data from the old and delete the old.

    But both methods are not very good practice. You normally would use a linked list, or similar structures.
    Please don't forget to rate users who helped you!

  5. #5
    Join Date
    Dec 2005
    Posts
    71

    Re: how to autogenerate array?

    can anyone teach me how to use dynamic array?

  6. #6
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Re: how to autogenerate array?

    you can teach yourself.

    Search the web for std::vector.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  7. #7
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: how to autogenerate array?

    See this excellent article in CG.
    http://www.codeguru.com/Cpp/Cpp/cpp_...icle.php/c4027
    quoted from C++ Coding Standards:

    KISS (Keep It Simple Software):
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.

    Avoid magic number:
    Programming isn't magic, so don't incant it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)