473,774 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

public function calls

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::myFunc tion();
method 2:
myClass myObject;
myObject.myFunc tion();

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
Jul 19 '05 #1
3 8867
BlueDoze escribió:
method 1:

myClass::myFunc tion();


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

Regards.
Jul 19 '05 #2
> 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
Jul 19 '05 #3

"BlueDoze" <bl******@yahoo .com> wrote in message
news:a5******** *************** ***@posting.goo gle.com...
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::myFunc tion();
method 2:
myClass myObject;
myObject.myFunc tion();

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.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2687
by: rl | last post by:
Hi out there, I'd like to know sth about the costs of a function call in php and the handling of character arrays (init size, enlargement steps of allocated memory, technique on enlargement -> full copy or virtual array spread in chunks over mem). The reason of my question is the following: // many function calls with smaller char arrays and less concats echo('wkjksdbjvsdnklvsDVL'.$a.'vfaadf');
10
4294
by: Michael | last post by:
Guys, I'm interested in how the compiler implements function calls, can anyone correct my understanding/point me towards some good articles. When a function is called, is the stack pointer incremented by the size of the variables declared in the called function, and then the function will know where these are in memory relative to the current stack pointer position. ALso how are variables returned, is that by a set position in the...
4
2474
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called themselves, or should i return a code to main and handle the error there? If i don't return them to main, except for the structure, what use is the main function except for calling functions?
10
2186
by: Nitin | last post by:
Ppl , Want to have ur opinions on having function calls like the one stated below: function funcA ( struct A *st_A , struct B *st_B ) { st_A->a = st_B->a
6
3493
by: pakis | last post by:
I am having a problem of pure virtual function call in my project. Can anyone explaine me the causes of pure virtual function calls other than calling a virtual function in base class? Thanks
1
1578
by: Lee Harr | last post by:
I have a view like this: CREATE or replace VIEW program_member_this_year AS SELECT DISTINCT person.person_id FROM unit.person, unit.visit WHERE unit.person.person_id = unit.visit.person_id AND visit.program_id = this_program() AND
7
2129
by: alexander.stippler | last post by:
Hi I wonder if their will be a performance penalty in the following situation due to virtual function calls: class Interface { public: virtual void methodA() = 0; virtual void methodB() = 0;
6
2263
by: Dasn | last post by:
Hi, there. 'lines' is a large list of strings each of which is seperated by '\t' I wanna split each string into a list. For speed, using map() instead of 'for' loop. 'map(str.split, lines)' works fine , but... when I was trying: I got "TypeError: 'list' object is not callable".
16
3284
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.