public function calls

B

BlueDoze

I want to know the difference between the following 3 methods of
calling a public function, which method is better and why

method 1:

myClass::myFunction();


method 2:
myClass myObject;
myObject.myFunction();

method 3:
myClass * pMyObject;
pMyObject->myFunction();

I know the difference between 2 and 3, but i'd like to know the
differences between 1 and the others

BlueDoze
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

BlueDoze escribió:
method 1:

myClass::myFunction();

You call this way when myFunction is a static member function of
myClass.

Regards.
 
O

.oO LGV Oo.

method 3:
myClass * pMyObject;
pMyObject->myFunction();

and method 3 is generally used for polymorphism ; if pMyObject points to a
derived class of myClass and if myClass declares virtual functions, then you
get polymorphism
 
J

jeffc

BlueDoze said:
I want to know the difference between the following 3 methods of
calling a public function, which method is better and why

method 1:

myClass::myFunction();


method 2:
myClass myObject;
myObject.myFunction();

method 3:
myClass * pMyObject;
pMyObject->myFunction();

I know the difference between 2 and 3, but i'd like to know the
differences between 1 and the others

Method 1 would be used in 3 cases:
a) myFunction is a static function, being called from somewhere outside
myClass
b) it's a function of the base class, where it's being called from a derived
class of myClass
c) it's a member function being called from another function of myClass.

In the case of c) it's not necessary to prefix with myClass - in fact it
would be redundant and confusing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,827
Members
47,373
Latest member
Desiree036

Latest Threads

Top