 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Roman Simkin Guest
|
Posted: Mon Oct 27, 2003 8:14 pm Post subject: What is the meaning of returning a value of a static type |
|
|
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
|
Posted: Mon Oct 27, 2003 8:29 pm Post subject: Re: What is the meaning of returning a value of a static typ |
|
|
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
|
Posted: Mon Oct 27, 2003 8:34 pm Post subject: Re: What is the meaning of returning a value of a static typ |
|
|
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
|
Posted: Mon Oct 27, 2003 8:34 pm Post subject: Re: What is the meaning of returning a value of a static typ |
|
|
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 |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|