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 

What is the meaning of returning a value of a static type

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





PostPosted: Mon Oct 27, 2003 8:14 pm    Post subject: What is the meaning of returning a value of a static type Reply with quote



Hi,

As far as I know, a static variable is a variable that belongs to a function
or a class (are there any other options?). I've seen somewhere a function
that *returns* static types - something like:

static [const] someType myFunction() {...}

What is the meaning of it?? Or did I get something wrong?

Thanks!

Roman.


Back to top
Alf P. Steinbach
Guest





PostPosted: Mon Oct 27, 2003 8:29 pm    Post subject: Re: What is the meaning of returning a value of a static typ Reply with quote



On Mon, 27 Oct 2003 22:14:23 +0200, "Roman Simkin" <falland (AT) inbox (DOT) lv> wrote:

Quote:
As far as I know, a static variable is a variable that belongs to a function
or a class (are there any other options?).

It can also be at namespace/global scope.


Quote:
I've seen somewhere a function
that *returns* static types - something like:

static [const] someType myFunction() {...}

What is the meaning of it?? Or did I get something wrong?

You did get something wrong.

In this context the word 'static' means "internal linkage" -- for
the function, not the return value.


Back to top
Julián Albo
Guest





PostPosted: Mon Oct 27, 2003 8:34 pm    Post subject: Re: What is the meaning of returning a value of a static typ Reply with quote



Roman Simkin escribió:

Quote:
As far as I know, a static variable is a variable that belongs to a function
or a class (are there any other options?). I've seen somewhere a function
that *returns* static types - something like:

static [const] someType myFunction() {...}

That static does not apply to the type of the return value, it applies
to the function, making it static.

static out of a function has a differente meaning, it marks his
parameter as non extern, that is, it's not seen from different units of
compilation.

Regards.

Back to top
Ali R.
Guest





PostPosted: Mon Oct 27, 2003 8:34 pm    Post subject: Re: What is the meaning of returning a value of a static typ Reply with quote

That's not what you think. That's a static member function. When you
declare a member function static, you will have access to the function
outside of the class, without instantiating an instance of the class. One
thing about this is that the function will not have access to any of the
none static members of the class. The Static member function is a very good
method for singleton classes. Try reading Effective C++, More Effective
C++, and Design Patterns.

Ali R.

class A
{
public:
static int DoSomething();
private:
int m_Counter;
static int m_StaticCounter;
}

int A::DoSomething()
{
m_StaticCounter++; //this is fine
m_Counter++; //error!!!
}
main()
{
A::DoSomething(); //this is also fine.
}


"Roman Simkin" <falland (AT) inbox (DOT) lv> wrote

Quote:
Hi,

As far as I know, a static variable is a variable that belongs to a
function
or a class (are there any other options?). I've seen somewhere a function
that *returns* static types - something like:

static [const] someType myFunction() {...}

What is the meaning of it?? Or did I get something wrong?

Thanks!

Roman.





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

 
 


Powered by phpBB © 2001, 2006 phpBB Group