Thread: String Addition Problem...

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    7stud: not a good question when it comes to pointers.

    Yeti: Yes, it would. However, it is not a good idea to do it that way, because you don't know how large the array is, and out-of-bounds access is all too easy. The typical way is to pass the size along with the pointer, i.e.
    void a_function(int *passed_array, std::size_t passed_array_size)
      if(passed_array_size < 6) {
        throw std::out_of_bounds("Array is too small.");
      passed_array[5] = 1;
    Of course, in C++ it's even better to pass a reference to a boost::array or a std::vector.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #17
    Join Date
    May 2005
    Many, many miles from the center of the Earth.
    Vector, that's what I was looking for. Thanks very much
    If a=b, and b=c, then a=c, except where void and prohibited by law...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM