471,595 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

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.
Jul 19 '05 #1
3 2277
On Mon, 27 Oct 2003 22:14:23 +0200, "Roman Simkin" <fa*****@inbox.lv> wrote:
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.

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.

Jul 19 '05 #2
Roman Simkin escribió:
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.
Jul 19 '05 #3
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" <fa*****@inbox.lv> wrote in message
news:3f******@news.bezeqint.net...
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.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

140 posts views Thread by Oliver Brausch | last post: by
51 posts views Thread by jacob navia | last post: by
669 posts views Thread by Xah Lee | last post: by
22 posts views Thread by nospam_news | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.