Thread: Dynamic class variable

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    24

    Dynamic class variable

    I have a base class, A, with an inquiry method bool isB(), and two derived classes, B and C, that inherit from A. I also have a container class, D, with a variable, x, and its respective accessor, x(). My problem, is that x needs to be a pointer to type B --or-- C, so that when I do something like D *test = new D();, then test->x() will either be a pointer to B or a pointer to C, which I won't know until run time and could then check using the inherited method, test->x()->isB(), which will be set within B and C's constructors to true or false, respectively.

    So, my question is, what should the data type for x and return type for x() be? I was thinking like void *, but wasn't sure if that's correct or not.
    Last edited by drrcknlsn; 01-18-2008 at 01:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. global and static variable in a class delivered in a DLL
    By George2 in forum C++ Programming
    Replies: 16
    Last Post: 04-13-2008, 08:19 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. dynamic array of base class pointers
    By Corrington_j in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2003, 05:58 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM