Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@prototype-G9Gn5k • Sep 4, 2014
I am not aware of actual thing but my common sense says they don't have same memory.
I mean, I can write my function name as add and do some multiplication operation there. What I want to say is, just because the name is same, you cannot assume the contents will be same. add(int, int) and add(int,int,int) are two different independent function with their own contents. Hence they must have their own space in the memory.
According to me the compiler puts the reference of appropriate function depending on the arguments at the compile time. -
@harmanveer-xeYnUU • Sep 4, 2014
then whats the use of functions having same same? I mean why polymorphism? We can define two separate functions.
Is it only for user convenience? -
@ramani-VR4O43 • Sep 4, 2014
A square, a rectangle or a parallellogram is a subclass of the superclass quadrilateral. In programming it is sometimes advantageous to refer to a quadrilateral for all quadrilaterals and let the actual action be done specific to the special case at runtime.
Some details are here:
#-Link-Snipped-#
#-Link-Snipped-#
<a href="https://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29" target="_blank" rel="nofollow noopener noreferrer">Polymorphism %28Computer Science%29</a> -
@radha-BTDzli • Sep 5, 2014
see whenever u call a function in memory there is a data structure which is called a stack which is formed in the memory,and in that function u have the local variables which are ur actually arguments and the processing which needs to be done .Harmanveerthen whats the use of functions having same same? I mean why polymorphism? We can define two separate functions.
Is it only for user convenience?
whether u make 7 functions of same name it doesnt matter ,u will have a stack maintained of those 7 functions but obviously something would differentiate all of them,say fun(int) calls fun(int,float) so at the bottom of the stack i have fun and on top of stack i have fun(int,float).
and i would just suggest u that i may not be clearing ur doubt properly so plz read on net about function calling which is implemented through stack -
@prototype-G9Gn5k • Sep 10, 2014
What you asked is just a very basic form of polymorphism. There's much more to the polymorphic capabilities provided by the OOP, especially C++.Harmanveerthen whats the use of functions having same same? I mean why polymorphism? We can define two separate functions.
Is it only for user convenience?
Coming to the question, lets just say you created a library. Some other developer might be just using your functions. Don't you think it'll be handy to call a function with same name to perform a 'similar' function on different data types? For eg. Adding of two integers is called "addition" and the same is true for adding two floats. I find it cool that I can just say add(x,y) and compiler appropriate function gets called instead of making two functions with different add_int(x,y) and add_float(m,n).