+ 3
When do we call function as function(object); and whn as object.function(); in object oriented programming in c++.
when to use
4 Answers
+ 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.
+ 11
@chris Your explanation might be better. Just post it. :>
+ 11
Thanks @Hatsy Rei!
That was helpful!
+ 6
I was going to explain this question but Hasty Rei bet me on commenting first again