cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : General C++ Programming : Can we make a non-member function static...
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  Can we make a non-member function static?

nezi (9)
In C++,Can we make a non-member function as static?If yes,then in which situation should we make such kind of functions?How do they work?What will be the relevance to make these functions?
|
ropez (312)
If you mean something like this:
1
2
3
4
static void foo()
{
  // ...
}

It means that the function is only visible in the file where it was declared. It means that you can't call it from another cpp file, and that you can have several static functions named foo() in several source files.

This is a common way to add internal helper functions that are used internally in a source file. However, using the static keyword is kind of old-fashioned, because in C++ you can use an unnamed namespace to achieve the same effect:

1
2
3
4
5
namespace {
void foo()
{
}
}

|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us