static C C++ÓïÒå
´æ´¢ÆÚstorage duration(extent)£¬ ָΪ¶ÔÏóÅäÖõÄÄÚ´æµÄ´æ»îÆÚ£¬±ÈÈçlocal extent
Éú´æ¿Õ¼äscope£¬Ö¸¶ÔÏóÔÚ³ÌÐòÄڵĴæ»îÇøÓò£¬¼´¿É±»·ÃÎʵķ¶Î§£¬±ÈÈçfile scope, static scope, local scope
C
local static object
º¯ÊýÄÚ²¿µÄobject£¬¾ßÓÐlocal scope£¬µ«ÊÇÿ´Îº¯Êý±»µ÷Óúó¸Ã¶ÔÏóµÄÄÚ´æ²»ÇåÀí£¬µ½Ï´ε÷Óû¹±£³ÖÔ×´
file static oject£¬static function
Ö»Óб»±àÒëÎļþµÄÉùÃ÷µãÖ®ºó²ÅÄÜʹÓøÃobjectºÍ¸Ãfunciton£¬´ïµ½Òþ²ØÍⲿ¶ÔÏóµÄÄ¿µÄ
C++
Ö±½Ó¶¨ÒåÔÚÎļþÖеıäÁ¿(ÎÞÂÛÊÇ·ñ¼Óstatic)£¬¾ßÓÐfile scope£¬¼´static scope£¬ÄÚ´æÒ»Ö±µ½³ÌÐò½áÊø²ÅÊÍ·Å
local static object
º¯ÊýÄÚ²¿µÄobject£¬¾ßÓÐlocal scope£¬µ«ÊÇÿ´Îº¯Êý±»µ÷Óúó¸Ã¶ÔÏóµÄÄÚ´æ²»ÇåÀí£¬µ½Ï´ε÷Óû¹±£³ÖÔ×´
static class member
classÄÚΨһµÄÒ»·Ý(¼´¸ú¶ÔÏóÎÞ¹Ø)£¬¿É¹²ÏíµÄ£¬member
const static class member
ͬstatic class member£¬µ«ÊÇ¿ÉÇÒ½ö¿ÉÔÚÉùÃ÷ʱ¸³Öµ
static class functions
²»´æÈ¡ÈκÎnon-static membersµÄº¯Êý
#pragma once
#include <string>
using namespace std;
class MyClass1
{
public:
MyClass1(void);
~MyClass1(void);
static void Test(void); //static class function
private:
static string _name; //static class member
static int _age; //static class member
int _testi;
const static int _size = 1; //const static class member
};
static int mytest2i = 0;
#include "StdAfx.h"
#include "MyClass1.h"
int MyClass1::_age;
string MyClass1::_name = "test"; //initialize here
MyClass1::MyClass1(void)
{
mytest2i = 0;
}
MyClass1::~MyClass1(void)
{
}
void MyClass1::Test(void)
{
MyClass1::_age = 1;
}
Ïà¹ØÎĵµ£º
VB
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = i1
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
MSComm1.InBufferCount = 0
& ......
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include ".\sqlite3_lib\sqlite3.h"
static int _callback_exec(void * notused,int argc, char ** argv, char ** aszColName)
{
int i;
for ( i=0; i<argc; i++ )
......
2008-07-07 23:32:21
1.ÄÚ´æ·ÖÅ䷽ʽ
ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
[1]´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄÕû¸öÔËÐÐÆÚ¼ä¶¼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static±äÁ¿¡£
[2]ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯ÊýÖ´ÐнáÊøÊ±ÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ ......
C++ÄÚ´æ·ÖÅäÃØ¼®—new£¬malloc£¬GlobalAllocÏê½â
......