You are not logged in.

sumsin

Trainee

  • "sumsin" started this thread

Posts: 75

Location: INDIA

  • Send private message

1

Tuesday, August 9th 2005, 9:59am

difference ? ( Solved )

hi

have a look at code
class Base
{
...
};
class Derived: public Base
{
...
};

now what is the difference between the declaration mentioned below:

Base *Var = new Derived();

and

Derived *Var = new Derived();


bye

This post has been edited 1 times, last edit by "sumsin" (Aug 10th 2005, 6:22am)


Michiel

Trainee

  • "Michiel" is male

Posts: 112

Location: The Netherlands

Occupation: Student / Programmer

  • Send private message

2

Tuesday, August 9th 2005, 4:32pm

The first one only has -> access to the Base class public members. The second has access to all public members.

You can make the second from the first like this: dynamic_cast<Derived*>(BaseVar)

It is sometimes useful to use the base class if you want to pass different kinds of objects derived from it to a function or keep an array of different kinds of derived objects.

sumsin

Trainee

  • "sumsin" started this thread

Posts: 75

Location: INDIA

  • Send private message

3

Wednesday, August 10th 2005, 6:22am

Runtime Polymorphism(Solved)

Thanks.

And I also found that it is also known as "Runtime Polymorphism";