dynamic_cast help

This is a discussion on dynamic_cast help within the C++ Programming forums, part of the General Programming Boards category; Forgot to enable RTTI. Thanks... ignore post...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    54

    dynamic_cast help

    Forgot to enable RTTI. Thanks...

    ignore post
    Last edited by JeremyCAFE; 02-13-2006 at 07:50 PM.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    Why don't you just scan the page from your homework book and we can see the whole thing and maybe do the next question for you, too.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    Or we can be rude and be of no help. thanks ass.

    Yes, I am working on a lab. If you read I didnt ask for someone to do it for me. The lab has to do with getting user input for derived classes and store them into a base class pointer. I have already done that, im trying to take it further to figure out how somet things work. I asked what is going on so i can understand how to use dynamic_cast better.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    where do I enable RTTI? That is probably where my problem is.

  5. #5
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    dynamic_cast is used as follows:

    Code:
    class base
    {
    };
    
    class derived : public base
    {
    };
    
    void func(base& b)
    {
        derived* pd = dynamic_cast<derived*>(&b);
        if (pd)
       {
           cout << "it's a derived class!";
       }
    }
    generally, dynamic_cast should be avoided. there are almost always better ways of doing the same thing (virtual functions, etc)
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

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