Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Why can't p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 9 Topic 9558 of 9775
Post > Topic >>

Re: Why can't pass vector of "Derived" to function that takes vector of "Base"?

by Rob <someidunknown1234@[EMAIL PROTECTED] > Apr 29, 2008 at 11:13 AM

> A template instantiated twice, one holding type T1 and the other type
> T2, are completely unrelated types according to the rules of the C++
> type system.  As such, it's no different than trying to pass a Person
> structure to a function expecting a Shape object.
>
> Now logically, you might think that if the relation****p between two
> types T1 and T2 are polymorphic, then arrays or vectors of them ought
> to be also, but it just isn't so.

Thank you everyone for the responses. I understand now. It is
different in Java and I think that threw me off.

> Fist, be glad you used a vector and not a raw array (passed as a
> pointer) as that *would* compile, and would have devastating results.
> Consider the issue: How do you index into an array?  The way it works
> is through pointer arithmetic on the size of the array element.

Well, while I know this is how it is, two things:

1. They could have overriden the []operator so that it works with non-
contiguos data or with data of changing sizes.
2. A vector of bools is exactly that - it's not a normal container and
the data is retrieved through indirection so they have done something
like that before

It might have given a performance hit but I think it could be done.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 9 Posts in Topic:
Why can't pass vector of "Derived" to function that takes vector
Rob <someidunknown1234  2008-04-28 16:05:53 
Re: Why can't pass vector of "Derived" to function that takes ve
Chris Uzdavinis <cuzda  2008-04-28 20:36:06 
Re: Why can't pass vector of "Derived" to function that takes ve
Lance Diduck <lancedid  2008-04-28 20:35:36 
Re: Why can't pass vector of "Derived" to function that takes ve
"Hakusa@[EMAIL PROTE  2008-04-28 23:22:39 
Re: Why can't pass vector of "Derived" to function that takes ve
nickf3 <nickf3@[EMAIL   2008-04-28 23:22:53 
Re: Why can't pass vector of "Derived" to function that takes ve
David Pol <david@[EMAI  2008-04-29 10:38:26 
Re: Why can't pass vector of "Derived" to function that takes ve
Brendan Miller <catphi  2008-04-29 10:37:22 
Re: Why can't pass vector of "Derived" to function that takes ve
Anand Hariharan <mailt  2008-04-29 10:44:31 
Re: Why can't pass vector of "Derived" to function that takes ve
Rob <someidunknown1234  2008-04-29 11:13:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:31:08 CDT 2008.