Why can't this method take derived class?

This is a discussion on Why can't this method take derived class? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia Perhaps the problem is that "to" has a different meaning to you than me. I was ...

  1. #31
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by Elysia View Post
    Perhaps the problem is that "to" has a different meaning to you than me.
    I was looking at the decorated name for the compiler. Since vector is a class, it is part of the mangled name the compiler/linker sees. Since my Visual Studio is borked, I can't do a test right now.
    To me "vector OF type x" sounds like an array of type x. But vector is a class and is not a native array and thus isn't treated the same way by the compiler.
    How the compiler mangles names is implementation-dependent. Conceptually, a vector is a container that holds objects. What is that vector<int> holding? It's a vector of integers.

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    I don't know if the above examples makes any more sense?
    The vector object is part of the type, which was what I was trying to imply by naming it vector-to-A.
    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.

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by Elysia View Post
    Perhaps the problem is that "to" has a different meaning to you than me.
    Probably. Frankly, though, past experience gives me confidence that my meaning would be understood by more people. But perhaps you would care to explain your meaning.

    Here's mine: A vector is a container. A container cannot be "to" something, because that doesn't make semantic sense. Containers, like buckets, bowls, arrays etc. are "of" something.

    To me "vector OF type x" sounds like an array of type x. But vector is a class and is not a native array and thus isn't treated the same way by the compiler.
    I don't know what you're getting at. First, vector is a class template, not a class, but that's a minor quibble and not the point at all.
    But "vector is not a native array" - well, duh!

    vector<A> is vector + A you could say.
    A[] is just A (in an array, but I don't know if you could argue that's a type).
    No. vector<A> is vector<A> and A[] is A[]. (And more specifically, A[N] is A[N], since A[] is an incomplete type.)

    The problem is that the vector sees vector<A> and A[] as something else entirely.
    That's just sane behaviour. Why should it treat vectors (dynamically expanding arrays) and built-in arrays (statically fixed-size arrays) the same?

    And so it sees vector<A> and vector<B> as complete types respectively and because vector<B> does not inherit from vector<A>, it assignment is illegal.
    It could be any object.

    Code:
    template<typename T> class MyClass { };
    
    class A { };
    class B: public A { };
    
    A* p;
    B b;
    p = &b; // OK
    
    MyClass<A>* p2;
    MyClass<B> b2;
    p2 = &b2; // Illegal. MyClass<B> does not inherit from MyClass<A>.
    I still don't see your point. Read my first post in this thread again: such an assignment MUST be illegal, by the rules of object-oriented design and its must fundamental idea, the Liskov Substitution Principle. A mutable container of a type is not a subtype of a mutable container of its supertype, no matter what kind of container it is.
    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

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Let it be said then. I don't we'll get any further and I think the answer has already been given, by more than one. Though using C++ terms such as your last statement, I think, is confusing to a lot of people.
    Not everyone is a master.
    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.

  5. #35
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Real world example time. Let's imagine you went to KFC and wanted lots of chicken to share with your mom and dad. I dunno if they have that where you live, but do your best to think of a similar joint.

    Now, this is important - if you ordered a bucket to chicken, the clerk will correct you just to make sure she understood your broken English. Same thing here with vectors and other containers, you can imply that a vector is part of the type (or its relation with the type it contains) simply with "of" instead of "to." "to" implies a direction like "from" does: Don't misuse your prepositions.

    Maybe the fact that we have to explain it to you confuses you, but that doesn't mean that we have to explain it to anyone else.

  6. #36
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    I know english and I'm not confused.
    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.

  7. #37
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I think part of the confusion might also have to do with English-to-X conversion. I'm not sure what Elysia's native language is, but maybe To and Of have slightly different translations, just like a lot of people here keep on saying they have a "doubt about ..." when they really have a "question about ...".
    Either that or she might be thinking in terms of how the compiler sees vector<x> rather than how Humans interpret it?

  8. #38
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    I'm pretty sure that part of the reason we get into these discussions is because she is working under the assumption that everyone who asks a question here is confused. In response, she's making C++ simpler than it needs to be, infact, so simple it tends to be broken on a fundamental, logical level. For example, even if she is thinking about "how the compiler sees vector<x>," that matter has no relevance to newbies. They could care less. And as people pointed out, it's wrong to think that anyway.

  9. #39
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    YOU may think that. Doesn't mean everyone does. Manav understood the example perfectly fine.
    Don't put everyone on the same level as you.

    And if some Americans can't even spell language right, who is to say they can differentiate between "to" and "of"? They may have different means for different people.

    Not everyone are geniuses. Don't eat me every time you can't understand something I write.
    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.

  10. #40
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Quote Originally Posted by Elysia View Post
    Don't put everyone on the same level as you.
    Back at you bud.
    And if some Americans can't even spell language right, who is to say they can differentiate between "to" and "of"? They may have different means for different people.
    But you're speaking English. To make sense, you have to understand the English definitions. English is not Esperanto and what to and from might mean to you doesn't matter. If English were a contest and you were a judge, perhaps then you could disqualify all of us and then (how convenient for you!) you wouldn't have to deal with the Americans that do understand English.
    Not everyone are geniuses. Don't eat me every time you can't understand something I write.
    How convenient for you.

  11. #41
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Who is arrogant now?
    I'm not top o' the world, but I do have a right to try explaining things the way I see without someone breathing down my neck.

    I never claimed to always be right, I am not always right, I don't know everything and I'm often wrong and I do accept that.
    Now let's stop this stupid argument because it's only going to get the thread locked.
    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.

  12. #42
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by Elysia View Post
    Who is arrogant now?
    I'm not top o' the world, but I do have a right to try explaining things the way I see without someone breathing down my neck.
    Nobody cares how you see it. What matters is being correct.

  13. #43
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    We'll see how long your humility lasts.

  14. #44
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Please stop with the personal critiques. It's annoying.

  15. #45
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    To be honest Elysia, I think your English is very good, and as far as I could tell English was your first language. If it's not well it's certainly better than some people's English who are native English speakers anyway.

    I think we all understand the point you were trying to make, but it wont stop anyone from using the more natural name for std::set<int> "a set of ints".
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Page 3 of 5 FirstFirst 12345 LastLast
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, 06:30 AM
  2. Callback function as class method
    By schifers in forum Windows Programming
    Replies: 39
    Last Post: 05-19-2008, 04:02 PM
  3. C++ Newbie - Derived Class Issue
    By Gipionocheiyort in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2007, 01:20 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21