Polymorphism In C++

Discussion in 'App Development' started by Grinda21, Mar 26, 2023.

  1. Grinda21

    Grinda21

    I'm performing research on type systems. In this project, I'm looking into how Variants, structural subtyping, universal polymorphism, and existential polymorphism are used in popular languages. Such functions are available in functional languages such as heskell and ocaml. But I'm curious whether a popular language like C++ has the above features. That is, how C++ was implemented.

    variants

    structural subtyping

    universal polymorphism

    Existential polymorphism.
     
  2. C++ is very powerful in polymorphism. IMO everything imaginable is possible, both static and dynamic polymorphism.
    See https://en.wikipedia.org/wiki/C++#Polymorphism
     
    Grinda21 and gkishot like this.
  3. Snuskpelle

    Snuskpelle

    What's the purpose of the thread? Are you looking for some kind of input? This is a trading forum after all. (And yeah, could be a bot...)
     
  4. d08

    d08

    It's a bot. Many on ET and they're somehow allowed to post. They create these random posts or just AI generated generic stuff.
     
  5. Grinda21

    Grinda21

    you literally made that up without being sure anyways if you know how to read i asked that i am curious that if C++ offers the capabilities listed above.
     
  6. Grinda21

    Grinda21

    Yes Thank you for that and also i read about it, here is what i understand that Unions can be seen of as a basic type of variation, but in truth, they are more of a primitive technique for memory layering (and unsafe).

    Also in C++, there is no structural typing, let alone subtyping. All of the kinds are nominal.

    Templates resemble universal polymorphism on the surface but are fundamentally different. These are essentially glorified macros with minimal to no type checking (like with macros, both checking and code generation happens after expansion).

    C++ does not support existential types (there is a limited form in Java, namely wildcards).
     
  7. d08

    d08

    You thought ET is the best place for computer science discussion? Not any of the SO channels for example?
     
  8. Grinda21

    Grinda21

    My bad
     
  9. You are mistaken b/c templates are strong typed, much like the rest of C++.

    Yes, a union allows to see the same memory location via different views. Ie. say as an integer, or as a char.
    I don't know what else you expect.

    Are you saying C++ has no structure type? Totally wrong as C/C++ is strong with structures and classes.
    I have no clue what you mean by subtyping. Maybe inheritance / derivation / subclassing? It's all avail in the language.

    "Existential types" are called abstract or generic types inc C++. It's all available.

    C++ is a practical language, not an academic-only.
     
    Last edited: Mar 27, 2023
  10. Do yourself a favor. Learn Rust instead. It was designed to essentially be it's replacement (no more memory issues, and no garbage collection). Or if you really want to learn C++, buy this book. It covers C++ 20 and modern practices of the language:

    Professional C++ (5th Edition) by Marc Gregoire

    Won't let me post Amazon link. First hit on google. Book with a red cover.
     
    #10     Apr 10, 2023