Help With Custom Dynamic Arrays

This is a discussion on Help With Custom Dynamic Arrays within the C++ Programming forums, part of the General Programming Boards category; Hi, I made my custom dynamic arrays, similar to vectors, and I have one problem with them. When I create ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    13

    Talking Help With Custom Dynamic Arrays

    Hi,

    I made my custom dynamic arrays, similar to vectors, and I have one problem with them. When I create a multidimensional array ( dynamic_array< dynamic_array<int> > for example) the compiled program crashes. I think that it is a problem with the destructor, which uses the inline function erase(), which basically sets the reserve and size to 0 and deletes the actual array with delete[]. I'm sort of new to C++ and it's my first programming language, so I would really appreciate some help and a solution to the problem.

    I have attached the source to this post.

    Thanks.
    Attached Files Attached Files

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,709
    Are you aware that you spelt memcpy wrong on line 49? That could be one reason it crashes because the array is never constructed properly.

    I suggest you break up your implementation and test parts of it so that you can be sure that they work. Asking us to debug your entire program is a little rude, and not good for you. How do you expect to learn how to program without debugging skills?

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Some lint:
    PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006

    --- Module: darray.cpp (C++)
    darray.cpp 22 [Info 1732] new in constructor for class 'array_error' which has no assignment operator
    darray.cpp 22 [Info 1733] new in constructor for class 'array_error' which has no copy constructor
    darray.cpp 23 [Warning 534] Ignoring return value of function 'std::strcpy(char *, const char *)' (compare with line 86, file c:\progra~1\borland\bcc55\include\_str.h)
    darray.cpp 24 [Info 818] Pointer parameter 'set' (line 21) could be declared as pointing to const
    darray.cpp 28 [Info 1762] Member function 'array_error::what(void)' could be made const
    darray.cpp 29 [Info 1762] Member function 'array_error::error(void)' could be made const
    darray.cpp 31 [Info 1712] default constructor not defined for class 'array_error'
    darray.cpp 53 [Info 1724] Parameter to copy constructor for class 'dynamic_array<<1>>' should be a const reference
    darray.cpp 70 [Info 1722] assignment operator for class 'dynamic_array<<1>>' does not return a reference to class
    darray.cpp 6 [Info 753] local enum 'array_error_codes' (line 6, file darray.cpp) not referenced
    darray.cpp 11 [Info 753] local enum '(untagged)' (line 11, file darray.cpp) not referenced
    darray.cpp 15 [Info 753] local class 'array_error' (line 15, file darray.cpp) not referenced
    darray.cpp 34 [Info 753] local template 'dynamic_array<<1>>' (line 34, file darray.cpp) not referenced
    darray.cpp 7 [Info 749] local enumeration constant 'array_error_codes::array_overflow' (line 7, file darray.cpp) not referenced
    darray.cpp 8 [Info 749] local enumeration constant 'array_error_codes::array_out_of_range' (line 8, file darray.cpp) not referenced
    darray.cpp 9 [Info 749] local enumeration constant 'array_error_codes::array_bad_alloc' (line 9, file darray.cpp) not referenced
    darray.cpp 12 [Info 749] local enumeration constant 'array_max' (line 12, file darray.cpp) not referenced

    --- Global Wrap-up

    darray.cpp 21 [Info 1714] Member function 'array_error::array_error(char *, unsigned short)' (line 21, file darray.cpp) not referenced
    darray.cpp 28 [Info 1714] Member function 'array_error::what(void)' (line 28, file darray.cpp) not referenced
    darray.cpp 29 [Info 1714] Member function 'array_error::error(void)' (line 29, file darray.cpp) not referenced
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    13
    Sorry if I was being rude citizen, I'll do my best to debug it (you were right, my debugging skills aren't the best ), and by the way, line 49 is ok, memccpy is a valid function defined in string.h.

    The arrays always get properly constructed and work ok when one dimensional, the problem was concerning only two and more dimensional ones, as I mentioned in my first post.

    Also thanks to Dave for your analysis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating and freeing dynamic arrays
    By circuitbreaker in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2008, 10:18 AM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. Dynamic (Numeric) Arrays
    By DavidB in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2006, 07:34 PM
  4. dynamic arrays and structures
    By godofbabel in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2002, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21