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++ )
......
C++内存分配秘籍—new,malloc,GlobalAlloc详解
......
C 中,
int 和long的范围一样,只能表示(-2^31~2^31)整数,即(-20亿~ 20亿)
unsigned int 与unsigned long 范围是(0 ~2^32),40亿多一点。
如果要表示更大一些的整数,这两种数据类型就不好用了,在ACM中经常要处理这样的数据类型,以前我的笨方法是做一个整形数组,每个a[i]存一位,这样加减 ......