1

What is ploymorphism??? Im new to oop, and wanna learn more abt it. Preferably in examples from pascal or cpp.

Comments
  • 1
    In that case, a search engine is your friend โ˜บ
    http://webopedia.com/TERM/P/...
  • 1
    Simply put, its a concept where the same thing can be used in different ways when applied to different contexts.

    Example:
    We can use the binary plus + operator to add numbers.
    In cpp (and many other languages) we can tell the compiler to add lets say a complex number (defined in a class) using the plus operator.

    This means ->

    Complex a(1,2), b(3,4);

    Instead of doing this ->

    a.add(b);

    We do this ->

    a = a + b;

    Ofcourse you have to programme this, as it wont happen automatically.

    Operator overloading is a very good example of polymorphism.
  • 0
    @harambae so... Its function overloading?
  • 1
    @linuxer4fun polymorphism includes function overloading, but its broader
  • 0
    @harambae oh well. I think, i know what to read about ;}
  • 1
    @linux4fun Polymorphism is where one thing can be used as if it was another.
    The example above that @harmabae did with the operator overloading is called Ad-hoc polymorphism (it can also be done with function overloading).

    There are 2 other types of polymorphism: paramteric and subtyping.

    Parametric polymorphism is basically allowing a function/class/type to be generalised. In C++ you can use templates (meta-programming) to write a datastructure, for example, for any type <T>. Meaning that this DS can hold int, double, string, etc... Holds well in the "write once for many uses" philosophy.
    In Java it's called 'Generics' instead of Templates.

    Subtyping polymorphism allows a function that uses a datatype T to use an object that is a subtype of T.
  • 0
  • 8
    @Letmecode Good thing too. :) He would get 20 answers all telling him to use jquery and then his question would get closed as too broad or some other bs like that by some bored mod on an ego trip.
  • 1
    @ElForritari 1+1=2 and 1+1=11
  • 3
    @Letmecode well, if sb needs help of community, asking for it is not forbidden
    And here answers come faster
  • 0
    @OrestH and thats why I dont get the jokes about "coding without so" especially while compilerbuilding every question of mine was turned down :(
  • 1
    They should give the asker +20 rep if your question wasn't downvoted in the first 30 min.
  • 1
    @lucas22 lel... Actually, because of my assembly learning, now im ip banned on so :(
  • 2
    Also, @linuxer4fun this is a duplicate and too broad question, pls read the guidelines before posting. - jk
  • 1
    @lucas22 you monster๐Ÿ‘พ ๐Ÿ‘พ๐Ÿ‘พ๐Ÿ‘พ๐Ÿ‘พ๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚
Add Comment