Thread: using containers with onjects

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    29

    using containers with onjects

    Hi There,

    I am currently learning how to use the STL classes, more specifically the containers list, vector and deque.

    Using primitive types to create a container seems very straight forward but how would you use them to create a container of like objects ?

    And how could you use the iterator to access the members of a user defined type iie a class ?

    Thanks,

    bigSteve
    bigSteve

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    One of the nice things about C++ is that well designed classes can act almost exactly like built in types. Provided your classes have the appropriate operators defined, you can use them in container classes with no trouble at all.

    >And how could you use the iterator to access the members of a user defined type iie a class ?
    The same way you would use an iterator with builtin types, just remember that you need to perform a member access operation to get to the interface.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Covariance with virtual functions and stl containers
    By cunnus88 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2009, 07:26 AM
  2. Noob STL question about Containers.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2009, 12:02 PM
  3. stl containers allocation in heap or stack?
    By sawer in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2006, 03:08 PM
  4. stl containers remove, clear
    By curlious in forum C++ Programming
    Replies: 3
    Last Post: 11-07-2004, 09:51 PM
  5. sorting containers of structs
    By bigSteve in forum C++ Programming
    Replies: 2
    Last Post: 01-06-2004, 02:50 PM