Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > member functions

Reply
Thread Tools

member functions

 
 
Wenjie
Guest
Posts: n/a
 
      07-01-2003
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
 
Reply With Quote
 
 
 
 
Josephine Schafer
Guest
Posts: n/a
 
      07-01-2003

"Wenjie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.


 
Reply With Quote
 
 
 
 
Klaus Eichner
Guest
Posts: n/a
 
      07-01-2003
"Wenjie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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>::<function>(), whereas non-static member
functions must be called via an object, like so: <object>.<function>()
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
overloading non-template member functions with template member functions Hicham Mouline C++ 1 04-24-2009 07:47 AM
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
Defining Non-Member Functions for Template Member Types flounder C++ 4 04-01-2009 11:59 PM
Member function pointers to member functions with default arguments Hamish C++ 3 01-25-2008 06:46 AM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments