Dynamic Type Check?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Genisio

    Dynamic Type Check?

    I know I have done this in Java, but is there a way to do it in C++?

    Type B and C inherit from type A.

    In a function, I want to check an instance of A (which can also be B or
    C), to see what it is, and move on... something like:

    A something;
    if( A.typeof(B) )
    {
    B somethingB = static_cast<B>( something);
    // Do things with the B members
    }
    else if ( A.typeof(C) )
    {
    C somethingC = static_cast<C>( something);
    // Do things with the C members
    }
    else
    {
    // Do things with the A members
    }

    I know I can accomplish something similar with virtual functions
    (polymorphism), but can the above be done in any way?

    Just curious.
    Brian

  • Michael Winter

    #2
    Re: Dynamic Type Check?

    On Thu, 15 Jan 2004 15:01:57 -0500, Brian Genisio <BrianGenisio@y ahoo.com>
    wrote:
    [color=blue]
    > I know I have done this in Java, but is there a way to do it in C++?[/color]

    You do realise that this is a JavaScript group, don't you?

    Try asking in comp.lang.c++

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • kaeli

      #3
      Re: Dynamic Type Check?

      In article <4006f1ec$1@10. 10.0.241>, BrianGenisio@ya hoo.com enlightened
      us with...[color=blue]
      > I know I have done this in Java, but is there a way to do it in C++?
      >[/color]

      AFAIK, yes.

      Go ask in a C group. :)


      --
      --
      ~kaeli~
      If a turtle doesn't have a shell, is he homeless or naked?



      Comment

      • Michael Winter

        #4
        Re: Dynamic Type Check?

        On Thu, 15 Jan 2004 20:46:21 GMT, Michael Winter
        <M.Winter@bluey onder.co.invali d> wrote:
        [color=blue]
        > On Thu, 15 Jan 2004 15:01:57 -0500, Brian Genisio
        > <BrianGenisio@y ahoo.com> wrote:
        >[color=green]
        >> I know I have done this in Java, but is there a way to do it in C++?[/color]
        >
        > You do realise that this is a JavaScript group, don't you?
        >
        > Try asking in comp.lang.c++[/color]

        I forgot to say the answer is, yes.

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Brian

          #5
          Re: Dynamic Type Check?


          "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
          news:opr1t3y8e0 5vklcq@news-text.blueyonder .co.uk...[color=blue]
          > On Thu, 15 Jan 2004 15:01:57 -0500, Brian Genisio <BrianGenisio@y ahoo.com>
          > wrote:
          >[color=green]
          > > I know I have done this in Java, but is there a way to do it in C++?[/color]
          >
          > You do realise that this is a JavaScript group, don't you?
          >
          > Try asking in comp.lang.c++
          >
          > Mike
          >
          > --
          > Michael Winter
          > M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]

          ARGHHHHH!!!!!!!

          I feel like a stooge. I actively follow two news groups...
          alt.lang.javasc ript, and alt.lang.c++. I accadently posted to the wrong
          group.

          The reason I feel so bad, is because I always get frustrated with incorrect
          postings to the different groups, weather it be java questions in the
          javascript group, or MFC questions in the C++ group.

          How about a C++ question in the javascript group?

          Blah,
          Brian


          Comment

          Working...