Thread: Noob STL question about Containers.

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 05: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, 08:40 PM
  5. question about STL
    By free2run in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2002, 12:12 PM