Abstraction

This is a discussion on Abstraction within the C++ Programming forums, part of the General Programming Boards category; If I have an array of pointers to objects of different classes that are derived from the same base class, ...

Thanks for the reply laserlight! But doesn't polymorphism mean that the members of a derived class are treated like those of its parent (or so Wikipedia says), whereas in my case it's the actually object that's treated like its parent, not its members?

But does polymorphism mean that the members of a derived class are treated like those of its parent (or so Wikipedia says), whereas in my case it's the actually object that's treated like its parent, not its members?

Stroustrup defines polymorphism as "providing a single interface to entities of different types". In your example, suppose that you have a virtual function overriden by the derived classes. Then, by looping over the array, you can call this virtual function, and the overriden versions for each object of a given derived class would be called, even though you appeared to call the base class member function. This is polymorphic behaviour since you accessed different member functions (of the derived classes) from a single interface (the base class virtual member function).

Sure, I agree about the use of overridden functions is polymorphism in the way you describe, but isn't the ability to treat the different objects (not their methods) as the same an example abstraction? If not, could you give me an example, as Stroustrup's definition of abstraction has left me non the wiser!

isn't the ability to treat the different objects (not their methods) as the same an example abstraction

No. The fact that you have user defined objects implies that abstraction. Think of abstraction as in saying "swap a and b" as opposed to "create a temporary t, assign a to t, assign b to a, assign t to b". Here, the implementation of a swap is hidden by the interface of a swap function. In the case of objects, the implementation of the objects is hidden by its interface, so we can talk in terms of a car rather than a specific collection of doors, windows, wheels etc (which themselves may be an example of abstraction, heh).