Noob STL question about Containers.

This is a discussion on Noob STL question about Containers. within the C++ Programming forums, part of the General Programming Boards category; Hi, I've just bought myself a copy of The C++ Standard Library and am reading about Containers (Vectors, Deque, Lists). ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148

    Noob STL question about Containers.

    Hi,

    I've just bought myself a copy of The C++ Standard Library and am reading about Containers (Vectors, Deque, Lists).

    Are containers simply like Arrays? For things like Ints, Floats and Chars, but the advantage of them is that they offer greater functionality, with things like begin() and end() etc? Is this where the STL come in, it offers greater functionality?

    Reading it, it comes across to me like they are the opposite of OO design.

    Any direction on where they fit in, in programming is appreciated. I'm not quite sure of their role just yet as I've only used things like Arrays and Structs up to yet.

    Many thanks for any help!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,941
    Quote Originally Posted by Swerve
    Are containers simply like Arrays?
    In the sense that they contain objects, yes. In particular, std::vector is a dynamic array container, and you will also encounter a fixed size array container example that is now available in somewhat different form as std::tr1::array.

    Quote Originally Posted by Swerve
    For things like Ints, Floats and Chars, but the advantage of them is that they offer greater functionality, with things like begin() and end() etc? Is this where the STL come in, it offers greater functionality?
    Yes, and not only for the built-in types, but for your own class types as well, assuming that they satisfy certain pre-conditions, e.g., they are copyable.

    Quote Originally Posted by Swerve
    Reading it, it comes across to me like they are the opposite of OO design.
    The standard containers are more an example of generic programming than object oriented programming. In particular, note that there is no inheritance, and that they do not have virtual functions.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148
    Thank you laserlight, you have answered some other questions I also had, for example Vectors can contain objects, and not just datatypes like Ints.

    bigthumbsup.jpg


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. super noob question
    By verbity in forum C++ Programming
    Replies: 6
    Last Post: 06-23-2007, 11:38 AM
  2. STL preformance question
    By l2u in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2006, 04:36 PM
  3. Noob question (redeclaring a array)
    By Demon.killer in forum C Programming
    Replies: 8
    Last Post: 10-21-2006, 12:06 PM
  4. STL container question
    By PJYelton in forum C++ Programming
    Replies: 8
    Last Post: 12-16-2002, 07:40 PM
  5. question about STL
    By free2run in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2002, 11:12 AM

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