Thread: List of derived classes

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    8

    List of derived classes

    If I have classes B, and C which are derived from class A, is it possible to store objects of B and C in an STL list declared as list<A> myList; or will these be stored as objects of class A only.

    When I iterate through the loop and run a display method I only seem to get details from the baseclass, A.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    store them as pointers:

    list<A*>

    and make sure the methods you are calling are virtual.

    hope this helps
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 09:27 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM