473,757 Members | 6,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

member functions

Hello,
I read someone posted assertions that even the (public) member
function is not static, there are probably only one copy of the
code in the executable. Then except the dependency/independency
on the lifecycle of the object, what is the significant
differences between public member functions and public static
member functions?

I have a problem behind the question: for some reason the object
has to be created with attributes under most of the cases, but
sometimes some of the member function is expected from outside
but at that case there are no object available since the attributes
input are not ready(but has no impact on the expected function).

Am I lost in the English instead of C++?
Best regards,
Wenjie
Jul 19 '05 #1
2 2840

"Wenjie" <go****@yahoo.c om> wrote in message
news:d2******** *************** ***@posting.goo gle.com...
Hello,
I read someone posted assertions that even the (public) member
function is not static, there are probably only one copy of the
code in the executable. Then except the dependency/independency
on the lifecycle of the object, what is the significant
differences between public member functions and public static
member functions?


I think you want to ask the semantic difference between a normal member
function and a static member function.

Static member functions apply to a class while member functions make sense
for individual class objects.
For e.g.. a Car class may have a public static member function int
totalcount ()
which returns the total number of Car objects created. Now this function
makes sense only for
Car class and not for individual Car objects. As opposed to this some
function like void drive () makes
sense only for objects of Car class and not for the class itself so it
should be a normal member function.

HTH.
Jul 19 '05 #2
"Wenjie" <go****@yahoo.c om> wrote in message
news:d2******** *************** ***@posting.goo gle.com...
Hello,
I read someone posted assertions that even the (public) member
function is not static, there are probably only one copy of the
code in the executable.
<long text about number of copies in an executable...>
As far as I am aware, compilers generate in general only one copy of a
member function in the executable, for both static and non-static member
functions, public or private alike. You should, however, consider inlined
and non-inlined functions: inlined member functions are generated in many
places in the executable, i.e. once for every call of that member function,
whereas non-inlined member functions are only generated once. You can
recommend to the compiler to inline a member function by placing its
definition inside the body of a class, but the compiler is free to decide
whether the function code is actually inlined or not.
The number of copies of a function code in the executable makes no
difference what so ever to the beheaviour or functionality of the program.
It does, however, impact the performance, i.e. size of the executable and
run-time.
<end of long text>
Then except the dependency/independency
on the lifecycle of the object, what is the significant
differences between public member functions and public static
member functions?
The most obvious difference is that static member functions can be called
without an object like so <class>::<funct ion>(), whereas non-static member
functions must be called via an object, like so: <object>.<funct ion>()
Also remember that static member functions can not access non-static class
members, whereas non-static member functions can access them.
I have a problem behind the question: for some reason the object
has to be created with attributes under most of the cases,
You probably mean that in most cases the program creates objects of a
certain class (this class, of course, has attributes such as member
functions and data members)
but
sometimes some of the member function is expected from outside
but at that case there are no object available since the attributes
input are not ready(but has no impact on the expected function).
You probably mean that the program calls a member function of a class
without an object

Here is the conclusion: in order to call a member function without an
object, this member function has to be static.
Am I lost in the English instead of C++?
I don't have any problem understanding your English.
Best regards,
Wenjie

Jul 19 '05 #3

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

Similar topics

4
7409
by: 0to60 | last post by:
I don't know if I have that terminology right, but does anyone know if static member functions (or free standing functions for that matter) are any less overhead than actual member functions that operate on an instance of that class? I'm writing a math calculator that responds to real time data and it needs to be FREAKY fast. To minimize the number of arguments that certain methods take, I have stored some data within a class and made...
2
1677
by: Thomas Matthews | last post by:
Hi, I have a hierarchy of classes and would like to create an array of pointers to member functions that could also contain pointers to the parent member functions as well. What is the syntax for this? #include <string> using std::string;
11
4614
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member variables". However, this doesn't seem entirely correct. It also doesn't mention whether static member functions can access protected and private member data and methods (and I couldn't spot this in the FAQ). I have a class row<Row> which derives from...
12
2089
by: Anthony Jones | last post by:
Just a bit of background: I'm one of a group of FORTRAN programmers, looking to switch to C++. We are trying to write a few simple examples to demonstrate the power of the language to our manager, so he will send us all on a conversion course. One of many reasons is that our code is littered with examples of: SUBROUTINE PRINT_ITEM(ITEM, ITEM_TYPE) IF (ITEM_TYPE .EQ. SQUARE) THEN CALL PRINT_SQUARE(ITEM)
22
2775
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void fun() {
13
2531
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member functions in common implementations? And where is the 'this' ptr tucked away at for POD structs with member functions? John
2
1931
by: Angus | last post by:
I have a member function, int GetLogLevel() which I thought I should change to int GetLogLevel() const - I made the change and it works fine. But in the function I am creating buffers and of course the buffers are filling up with data. So some variable values are changing. So what is rule for a const member function? Is it that only member variables cannot change? But local variables inside the function can?
5
4663
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
7
3971
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member functions. Is it normal how C++ Compiler can compile large class without any problem? Didn't C++ Compiler have rules to limit the number of member functions? One big object has complex operations how member variables and member functions can be...
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9737
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
7286
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
6562
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
5172
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...
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.