Thread: Why can't this method take derived class?

  1. #46
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Which was/is my point.
    I was merely trying to use an appropriate name I thought best for the explanation to differentiate a vector from an array.
    Everyone is free to use their own names, of course.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #47
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    the explanation to differentiate a vector from an array.
    I still don't understand why you feel that a vector is different from an array. (Aside from the obvious part about vector being dynamic.)

    And frankly, the fact that manav claimed to understand your example worries me.
    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

  3. #48
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #49
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    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.

  5. #50
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

  6. #51
    verbose cat
    Join Date
    Jun 2003
    Posts
    209
    Quote Originally Posted by manav View Post
    a side question:
    Quote Originally Posted by jEssYcAt
    repeat 3 [forward 40 right 120]
    what will that make?
    That makes an equilateral triangle in Logo.
    abachler: "A great programmer never stops optimizing a piece of code until it consists of nothing but preprocessor directives and comments "

  7. #52

    Join Date
    Apr 2008
    Location
    USA
    Posts
    76
    vector<B*> cannot be a subclass of vector<A*> because they are both actually the same class (std::vector), just templated.

    Quote Originally Posted by CornedBee View Post
    I still don't understand why you feel that a vector is different from an array ...
    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.

  8. #53
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

  9. #54

    Join Date
    Apr 2008
    Location
    USA
    Posts
    76
    Quote Originally Posted by Daved View Post
    You can have a class foo<T> that is a subclass of foo<U>...
    Woops, I wasn't aware of that...

    Quote Originally Posted by Daved View Post
    The point is why can you say array of ints but not say vector of ints
    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.

  10. #55
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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.

    they are both actually the same class (std::vector), just templated.
    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.
    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

  11. #56
    Banned
    Join Date
    Nov 2007
    Posts
    678
    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!

  12. #57
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  13. #58
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by CornedBee View Post
    The term is "bone-headed".
    But the skull is made of bones, so everybody is bone-headed?

  14. #59
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    But the skull is made of bones, so everybody is bone-headed?
    I think the term implies that there's ONLY bone all the way from the front to the back of the head - no soft grey in between. Although I have never researched the etymology of the term.

    --
    Mats
    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.

  15. #60
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  2. Callback function as class method
    By schifers in forum Windows Programming
    Replies: 39
    Last Post: 05-19-2008, 03:02 PM
  3. C++ Newbie - Derived Class Issue
    By Gipionocheiyort in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2007, 12:20 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM