It is different in sense that it does not work exactly as an array plus that a vector is a completely different type than an array (and the compiler sees it that way).
A vector<int> is also a completely different type than a vector<char> according to the compiler, even though most of us basically see them as two buckets both the same shape, color & material, but holding different things inside.
>> I was merely trying to use an appropriate name I thought best for the explanation to differentiate a vector from an array.
The question is how they are different and whether the different terminology properly expresses those differences. They are not different in that they are containers of objects, so changing the terminology in that spot confuses that fact.
vector<B*> cannot be a subclass of vector<A*> because they are both actually the same class (std::vector), just templated.
Even though they can serve the same purpose, they're not at all syntactically the same (esp. from the compiler's perspective), and the compiler won't necessarily treat them the same.
Last edited by rudyman; 04-29-2008 at 04:39 PM.
>> vector<B*> cannot be a subclass of vector<A*> because they are both actually the same class (std::vector), just templated.
This reasoning isn't valid. You can have a class foo<T> that is a subclass of foo<U>. In the case of vector you can't, but that's not because it's not possible in general.
>> Even though they can serve the same purpose, they're not at all syntactically the same
That's not the point. The point is why can you say array of ints but not say vector of ints? They are the same in that respect, that they are containers of some type.
Woops, I wasn't aware of that...
The point I was really trying to make (mainly in response to CornedBee) is that, regardless of their conceptual similarities, the compiler considers vector (which isn't anything more than a templated class) something very different than an array (which is a core language feature and has a different effect on the variable's type), meaning you do need to differentiate the two.
Last edited by rudyman; 04-29-2008 at 04:52 PM.
Well, you do differentiate the two: one is an array of T, the other is a vector of T. I don't see any reason to take it further than that, and I'm still waiting for Elysia's reason to do so.
No. Contrary to what you may think, a class template is not a class. std::vector is a class template, not a class. std::vector<int> is a class, as is std::vector<float>. They're two different, unrelated classes, in fact.they are both actually the same class (std::vector), just templated.
One term that has sown confusion here is "template class", which is why the term was declared undesirable. It has been excised from the C++0x working paper and replaced by "class template".
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I see that CornedBee was a little worried about me understanding Elysia's point:
As I already mentioned in the post, I was also confused about Elysia using 'to' instead of 'of', but then as the post explained, so, it made perfect sense to me!
And, for all you concrete mind peoples I don't care either way, you call it 'to' or 'of'
PS: concrete mind - means hard, fixed & not easy to change!
The term is "bone-headed".
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Or at least the bone is so thick that nothing can get through.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
One should strive for such a skull, should they not? At least someone who doesn't want objects to penetrate it.
But all arguments aside, conceptually I see a Vector as what the STL describes it as, a Container. A Container which holds types. Some of those types may be pointers to types, but that distinction doesn't affect what a Vector is conceptually.
CornedBee, Ha Ha!!
In case of my brain, it goes via ears and eyes
PS: I can see CornedBee coming holding a Lock and Key!!!