+ 3

When do we call function as function(object); and whn as object.function(); in object oriented programming in c++.

when to use

28th Apr 2017, 5:35 AM
Abhijeet Singh
Abhijeet Singh - avatar
4 Antworten
+ 13
Let's say you have a function in a class: class ValentinHacker { public: void function (int test) { cout << test; } }; // in your main function: int main() { ValentinHacker obj; // declare object of class int num = 0; obj.function(num); // prints num return 0; } ------- ------- The 'obj' in obj.function() is the class object to specify that function() belongs to the class. The 'num' in function(num) is a variable which is passed into the function.
28th Apr 2017, 5:42 AM
Hatsy Rei
Hatsy Rei - avatar
+ 11
@chris Your explanation might be better. Just post it. :>
28th Apr 2017, 5:46 AM
Hatsy Rei
Hatsy Rei - avatar
+ 11
Thanks @Hatsy Rei! That was helpful!
28th Apr 2017, 6:17 AM
Tusiime Innocent Boub
Tusiime Innocent Boub - avatar
+ 6
I was going to explain this question but Hasty Rei bet me on commenting first again
28th Apr 2017, 5:44 AM
chris
chris - avatar