Advanced Minds

  • Decrease font size
  • Default font size
  • Increase font size
  • default color
  • red color
  • green color
FireBoard
Welcome, Guest
Please Login or Register.    Lost Password?
c++ arrays Arrays in C++ - Why Frowned Upon (1 viewing) (1) Guests
Go to bottom Post Reply Favoured: 0
TOPIC: c++ arrays Arrays in C++ - Why Frowned Upon
#8305
Joe Gottman (Visitor)
Click here to see the profile of this user
Birthdate:
c++ arrays Arrays in C++ - Why Frowned Upon  
of what an Array Class might look like.    The main reason I know of is that arrays and inheritance don't mix well at all.  If class Derived inherits from class _base_, you can pass a pointer or reference to a Derived _object_ to any function that requires a _base_ _object_.  You can also pass an array ofDerived _object_s to a function that requires an array of _base_ _object_s, i.e.    void foo(_base_ my_base_[]);    Derived myderived[10]);   foo(myderived); This is INCREDIBLY dangerous. If Derived has any additional data members that _base_ doesn't have, then you will get some very mysterious errors as you advance through the array. Each time you increment your index variable you will move forward sizeof(_base_) bytes, while each _object_ actually in the array will actually be of size sizeof(Derived).  This will leave both you and the program hopelessly confused. See Scott Meyer's Effective C++ for more info. As for an Array class,  the Vector and Deque templates from the STL should take care of almost all of your array needs.  Use the Vector unless you need to do a lot of inserting into the front of the array; in that case use the Deque.  Both of these classes can grow as necessary, so you don't have to know at compile time the largest possible size of the array. (This is another reason why they are considered better that plain arrays.)
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
      Topics Author Date
    thread link
c++ arrays Arrays in C++ - Why Frowned Upon
Tim Higham 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Marcus B. Irven 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Joe Gottman 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Howard Lee Harkness 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Valentin Bonnard 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Bradd W. Szonye 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Howard Lee Harkness 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Bradd W. Szonye 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Kevin Frey 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Herb Sutter 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Jon Watson 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Sean D. 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Chris Waters 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
Paul D. DeRocco 2008/05/08 08:13
    thread link
thread linkthread link c++ arrays Arrays in C++ - Why Frowned Upon
David Vandevoorde 2008/05/08 08:13
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop
no auth no auth nieautoryzowano nieautoryzowano brak autoryzacji
chicken recipes ground beef recipes online fantasy games stub hub fan codes side liner emotional diving