| | |
static function? help
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 19
Reputation:
Solved Threads: 2
Member functions (and data members) of a class can be declared as static. This means that they do not belong to any particular instance of the class, but instead are similar to gloabal functions (or variables), but must be referenced using the scope of the class they belong to: Class::staticmemberfunction()
Static member functions cannot act on instance data members of a class.
The following link provides an online C++ tutorial, although it is a bit brief:
http://www.cplusplus.com/doc/tutorial/
There are many other free online resources for learning the basics of object oriented programming in C++ that can be found through a google search.
Static member functions cannot act on instance data members of a class.
The following link provides an online C++ tutorial, although it is a bit brief:
http://www.cplusplus.com/doc/tutorial/
There are many other free online resources for learning the basics of object oriented programming in C++ that can be found through a google search.
>can someone tell me what static does to the function?
http://www.embedded.com/98/9811/9811fe3.htm about halfway down, although the whole article is worthwhile.
http://www.embedded.com/98/9811/9811fe3.htm about halfway down, although the whole article is worthwhile.
when not in a class definition, 'static' means that the name should not be visible outside the compiled module. This is an older style and has been 'deprecated' by the standards committee, but people still use it all the time.
Here's an example:
Same applies for any declared variable:
static int foo;
int bar; // this could be found by the linker from another obj file.
Here's an example:
C++ Syntax (Toggle Plain Text)
// file A void ExportedRoutine() { } static void NonExportedRoutine() { }
C++ Syntax (Toggle Plain Text)
// File B // this asks the linker to find ExportedRoutine defined in some other file extern void ExportedRoutine(); // this won't work because the routine is 'static' and therefore not available // to the linker to be found... extern void NonExportedRoutine(); // will generate a linker error
Same applies for any declared variable:
static int foo;
int bar; // this could be found by the linker from another obj file.
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Chainsaw
when not in a class definition, 'static' means that the name should not be visible outside the compiled module. This is an older style and has been 'deprecated' by the standards committee, but people still use it all the time.
Here's an example:
C++ Syntax (Toggle Plain Text)
// file A void ExportedRoutine() { } static void NonExportedRoutine() { }C++ Syntax (Toggle Plain Text)
// File B // this asks the linker to find ExportedRoutine defined in some other file extern void ExportedRoutine(); // this won't work because the routine is 'static' and therefore not available // to the linker to be found... extern void NonExportedRoutine(); // will generate a linker error
Same applies for any declared variable:
static int foo;
int bar; // this could be found by the linker from another obj file.
if a variable is declared as static within a function, the variable is maintained and is available for future calls of the function in which it has been declared
![]() |
Similar Threads
- Indicate that a function call is calling a static function? (C++)
- Modifying Form's Clientsize in a static function (C)
- performance benefit by not calling static member function by object (C)
- HELP: class static function - compile errors (C++)
- static function problem (C++)
Other Threads in the C++ Forum
- Previous Thread: beginner
- Next Thread: arranging 4 for loop * triangles in line
Views: 3446 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






