C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Static functions

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Der Andere
Guest





PostPosted: Mon Jun 28, 2004 12:32 pm    Post subject: Static functions Reply with quote



Do non-member static functions exist? If yes, what is the sense of making a
non-member function a static function? Can these functions only access
static variables?

Cheers,
Matthias Treder




Back to top
John Harrison
Guest





PostPosted: Mon Jun 28, 2004 12:41 pm    Post subject: Re: Static functions Reply with quote




"Der Andere" <matieudeletethispart (AT) gmx (DOT) net> wrote

Quote:
Do non-member static functions exist? If yes, what is the sense of making
a
non-member function a static function? Can these functions only access
static variables?


Yes they do, but it's a completely different meaning of the keyword static.

A non-member static function cannot be accessed outside of the translation
unit in which it appears. That is the meaning of static when applied to a
function or variable outside of any classes or functions.

A translation unit is all the code in a single compilation, normally this
means one source file and the headers it includes.

john



Back to top
Alf P. Steinbach
Guest





PostPosted: Mon Jun 28, 2004 12:42 pm    Post subject: Re: Static functions Reply with quote



* Der Andere:
Quote:

Do non-member static functions exist?

All non-member functions are static.


Quote:
If yes, what is the sense of making a non-member function
a static function?

The word 'static' has a different effect when applied to a
non-member function.

The non-member function is already a static function.

What 'static' does to that function is give it internal
linkage so that it won't be visible outside the compilation
unit -- i.e., (over-simplified) the linker will not see it.

This use of 'static' is deprecated, and imposes the limitation
that the function cannot be used as a template argument.

The modern way is to instead place the function in an anonymous
namespace, but for convenience or simply out of habit many (including
me) prefer to use 'static'.


Quote:
Can these functions only access static variables?

Apparently this question does not make sense.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to top
Rolf Magnus
Guest





PostPosted: Mon Jun 28, 2004 12:43 pm    Post subject: Re: Static functions Reply with quote

Der Andere wrote:

Quote:
Do non-member static functions exist?

Yes.

Quote:
If yes, what is the sense of making a non-member function a static
function? Can these functions only access static variables?

No. A static function can only be called from the translation unit it is
defined in. It has internal instead of external linkage, just like
static variables in the same scope do.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.