Pointers to inherited classes

This is a discussion on Pointers to inherited classes within the C++ Programming forums, part of the General Programming Boards category; I have class #1. Class #2, is completely unrelated, class #3 is derived from #1, class 4 is derived from ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    Arrow Pointers to inherited classes

    I have class #1. Class #2, is completely unrelated, class #3 is derived from #1, class 4 is derived from #1, And class 5 had multiple inheritance from both #2 and #1. Class 6 contains a pointer to type class #1 (these are not the real names). Can that pointer also be used to hold the address of classes 3, 4, and 5? If not all, which ones? Thanks if you can help.

    Sean Mackrory
    sean_mackrory@hotmail.com

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You'll be able to use the pointer to call any virtual methods in the derived classes that are inherited from class 1 but if the pointer is to a class 5 instance then it will not be able to call any virtual methods derived from class 2 (unless you use a cast).
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  2. Help With Inherited Classes Needed
    By elliott in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2005, 08:05 AM
  3. Pointers, Classes, and Errors o my!
    By Scottc1988 in forum C++ Programming
    Replies: 12
    Last Post: 03-13-2003, 09:14 PM
  4. Pointers to classes
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2002, 09:25 PM
  5. question time (classes and pointers)
    By swarm in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2002, 10:33 AM

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