473,242 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 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 2355
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

140
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
41
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
33
by: James H. Newman | last post by:
I have a portion of code along the following lines: volatile unsigned char x ; unsigned int f(unsigned char *y) ; When I do unsigned int z = f(&x) ;
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.