Which derived class is it?

From: Brad Marts (marts_at_phy.duke.edu)
Date: 12/15/03


Date: Mon, 15 Dec 2003 10:34:48 -0700

I would like to have a function that takes as an argument a base class but
performs differently depending on which type of derived class is passed.
Can I tell which derived class is passed?

For example:

class Base
{ //...
};

class D1: public Base
{ //...
};

class D2: public Base
{ //...
};

void f(Base b)
{
// Do one thing if b is of type D1, Do another if b is of type D2
}

Is this the right idea? Or do I have to write multiple copies of f()
with arguments overloaded with the derived classes?

Brad



Relevant Pages

  • Re: Copy of derived object from pointer to base
    ... >> type is pointer to the derived class. ... class Derived: public Base ...
    (microsoft.public.vc.language)
  • Re: why it fails
    ... " Using " is be put in the begining of derived class. ... class D: public Base { ... using Base func; ... int func{ ...
    (comp.lang.cpp)
  • Re: Which derived class is it?
    ... > performs differently depending on which type of derived class is passed. ... I would certainly not write multiple copies. ... Let's say it's to display something about ...
    (comp.lang.cpp)