casting

This is a discussion on casting within the C++ Programming forums, part of the General Programming Boards category; Hello, I have a type Base and two identical types DerivedOne and DerivedTwo that are derived from Base. I receive ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    11

    casting

    Hello,

    I have a type Base and two identical types DerivedOne and DerivedTwo that are derived from Base.

    I receive a Base * I know is a DerivedOne*.
    Could I cast from DerivedOne* to DerivedTwo?
    If yes how?

    BR,
    Cristian

    PS
    processMessage(Base * msg)
    {
    DerivedOne* pDerivedOne = dynamic_cast<DerivedOne *> msg;
    HOW TO DO
    DerivedTwo * pDeriveTwo = CAST<> pDerivedOne? Is it possible?
    }

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    i don't think it's possible. while Base and Derived1 have all similar members, Derived1 and Derived2 can be very different.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    11

    casting

    Sorry for not being clear,

    Derived1 and Derived2 are identical, I receive a message Base* I know is Derived1*.
    Could I cast the message to Derived2?

    Cristian

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Casting
    By morvick in forum C++ Programming
    Replies: 2
    Last Post: 06-18-2007, 12:06 AM
  2. Casting Question (I think)
    By fayte in forum C Programming
    Replies: 6
    Last Post: 03-08-2006, 05:31 PM
  3. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 01:17 AM
  4. Type casting
    By Lionmane in forum C Programming
    Replies: 28
    Last Post: 08-20-2005, 03:16 PM
  5. question about casting pointers/other types also??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2003, 06:01 AM

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