473,406 Members | 2,847 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,406 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 2361
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.