static function? help

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 11
Reputation: mattcplusplus is an unknown quantity at this point 
Solved Threads: 0
mattcplusplus mattcplusplus is offline Offline
Newbie Poster

static function? help

 
0
  #1
Nov 16th, 2004
static void myInit()
{
PrimitiveType=GL_POLYGON;

LineSegments=3;
}

can someone tell me what static does to the function?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 19
Reputation: JC7 is an unknown quantity at this point 
Solved Threads: 2
JC7 JC7 is offline Offline
Newbie Poster

Re: static function? help

 
0
  #2
Nov 16th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: static function? help

 
0
  #3
Nov 16th, 2004
>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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: static function? help

 
0
  #4
Nov 17th, 2004
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:
  1. // file A
  2. void ExportedRoutine()
  3. {
  4. }
  5.  
  6. static void NonExportedRoutine()
  7. {
  8. }
  1. // File B
  2. // this asks the linker to find ExportedRoutine defined in some other file
  3. extern void ExportedRoutine();
  4.  
  5. // this won't work because the routine is 'static' and therefore not available
  6. // to the linker to be found...
  7. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 11
Reputation: mattcplusplus is an unknown quantity at this point 
Solved Threads: 0
mattcplusplus mattcplusplus is offline Offline
Newbie Poster

Re: static function? help

 
0
  #5
Nov 17th, 2004
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:
  1. // file A
  2. void ExportedRoutine()
  3. {
  4. }
  5.  
  6. static void NonExportedRoutine()
  7. {
  8. }
  1. // File B
  2. // this asks the linker to find ExportedRoutine defined in some other file
  3. extern void ExportedRoutine();
  4.  
  5. // this won't work because the routine is 'static' and therefore not available
  6. // to the linker to be found...
  7. 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.
Thats good information for me to know thanx, i was familiar with the use of static with regards to classes.

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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: static function? help

 
0
  #6
Nov 18th, 2004
>the variable is maintained and is available for future calls of the function in which it has been declared
However, this isn't as useful as it appears at first.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3446 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC