List of derived classes

This is a discussion on List of derived classes within the C++ Programming forums, part of the General Programming Boards category; If I have classes B, and C which are derived from class A, is it possible to store objects of ...

  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-28-2008, 12:24 AM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 09: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

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