inheritance, pointercast

Discussion in 'C++' started by Dan Cernat, Jul 31, 2003.

  1. Dan Cernat

    Dan Cernat Guest

    "Rasmus" <> wrote in message news:<bg61iq$2s5b$>...
    > Hi, here a quick question:
    >
    > I have class A,B,C where B and C is extended from A.
    >
    > I would like to construct A objects like:
    >
    > A *a3 = new A(a1, a2);
    >
    > and a3 should be an object of type B or C.
    >
    > Is this possible?
    > | true: How?
    > | false: Can you give me a nice solution?
    >
    > Thanks for your time
    > Rasmus



    A* a3 = new B(a1, a2);
    A* a4 = new C(a1, a2);

    provided B and C have such constructors. If not, use the apropriate
    constructors for B and C.

    /dan
     
    Dan Cernat, Jul 31, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,179
    Martijn van Steenbergen
    Dec 21, 2003
  2. Rasmus

    inheritance, pointercast

    Rasmus, Jul 29, 2003, in forum: C++
    Replies:
    0
    Views:
    289
    Rasmus
    Jul 29, 2003
  3. cppsks
    Replies:
    0
    Views:
    842
    cppsks
    Oct 27, 2004
  4. karthikbalaguru
    Replies:
    9
    Views:
    1,061
  5. Daniel Pitts
    Replies:
    27
    Views:
    1,942
    Mike Schilling
    Feb 27, 2008
Loading...

Share This Page