array and polymorphism

H

hpsoar

I have ream Item 3 in the famous More Effective C++, the title
is :Never treat arrays polymorphically. it warn us about misusage of
polymorphism. But I'm just not clear about the rational or reason, can
anyone give me a clearer explanation? and thank you
 
A

Alan Woodland

I

Ian Collins

hpsoar said:
I have ream Item 3 in the famous More Effective C++, the title
is :Never treat arrays polymorphically. it warn us about misusage of
polymorphism. But I'm just not clear about the rational or reason, can
anyone give me a clearer explanation? and thank you

Try compiling the example code and see what happens. The gist of the
problem is arrays of T decaying to pointer to T in function calls. So a
function with a parameter type const Base[] can be passed an array of
Derived[].
 
H

hpsoar

(e-mail address removed) wrote:

Context, please!

I think I understand it know, but I think frequently when we want to
manipulate an object we do it with a pointer of its base class type,
and analogically, when we want to manipulate an array of objects we
can naturally use an array of pointers of its base class type. So that
problem proved to be insignificant. What do you think ?
 
H

hpsoar

I think I understand it know, but I think frequently when we want to
manipulate an object we do it with a pointer of its base class type,
and analogically, when we want to manipulate an array of objects we
can naturally use an array of pointers of its base class type. So that
problem proved to be insignificant. What do you think ?

Ok, I wrote those words abouve before I read the article on
https://www.securecoding.cert.org/confluence/display/cplusplus/ARR39-...
, after I accomplish reading, I found myself conformed with the
author, thank you anyway.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top