0

Is functions also have different copies for different objects of same class?

I mean is function take different memory for different objects of same class or function made only once and independent of creating object

3rd Aug 2018, 5:20 PM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
16 odpowiedzi
+ 1
Prateek Chaturvedi it's compiler who does this for us... as soon as you create a function, function pointer is created by compiler while we build the code... for all other call to function in main file, function pointer is mapped and body of the function gets executed.... all member object calls same function through function pointer... body of function going to be executed is also same... but if you take values associated with object in member function, it will be different.. Feel free to ask if you have further doubt
4th Aug 2018, 11:57 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
thanks ketan lalcheta
4th Aug 2018, 11:59 AM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
0
function does not take memory... data member are culprit for memory once object are created... And static data member are common for all class objects
3rd Aug 2018, 5:25 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
please further elaborate this.like then how these member function able to access different objects if they made only.once
4th Aug 2018, 5:22 AM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
0
it means there is different functions pointer for different objects
4th Aug 2018, 12:05 PM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
0
no ..it's same...it is maintained by one per class... object numbers do not decide no of pointers for one function
4th Aug 2018, 12:07 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
means different for different functions but one per class
4th Aug 2018, 12:13 PM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
0
yes, one pointer for one function in a class...if you create a same function in other class, it's different pointer for that particular function in different class
4th Aug 2018, 12:14 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
OK ! but plz clear one point only that how then function got to know which object calls that function . So that it can use the data member of that function
4th Aug 2018, 12:16 PM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
0
with this , go with polymorphism study article... it is a good concept and whatever we have discussed will be used as base knowledge.. If you still have doubt on this discussion, I am willing to discuss...
4th Aug 2018, 12:16 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
here is a link to study internal mechanism of polymorphism, which may help to understand function call in normal scenario: https://stackoverflow.com/questions/2171081/how-c-implements-the-polymorphism-internally
4th Aug 2018, 12:19 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
it's this pointer... compiler pases it as internal argument to function...you can access object calling function with this pointer in function itself
4th Aug 2018, 12:21 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
let me put one code for this pointer and share here in some time
4th Aug 2018, 12:22 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
4th Aug 2018, 12:40 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
wait now let me tell you what I understand. when we create function, function pointer is created which gets binded with function call and when this call occurs this pointer gets passed which tell which object data to use to function. plz correct me if I am wrong
4th Aug 2018, 12:54 PM
Prateek Chaturvedi
Prateek Chaturvedi - avatar
0
just to make clear one point... this pointer points to object calling that function.. It's internal pointer available in function call when call happens from object...this facilitates data access of different objects in same function... what is function pointer... it's not this pointer... it is again a internal pointer that points to definition of function body... it's is not visible to us as a end programmer.. that mechanism is what compiler uses... EDIT : function pointer points to function body and not visible to us.. this pointer points to calling object and visible to by by this name
4th Aug 2018, 1:13 PM
Ketan Lalcheta
Ketan Lalcheta - avatar