allocator类
allocator<类名> 对象名;
对象.allocate(分配的空间大小);
RTTI
typeid(*对象名/类名).name() //输出类名
类成员的指针
成员类型全称 类名::* 对象=&类名.成员名; //对象指向类的成员
函数指针:
函数返回值类型(类名::* 指针名)(参数类型) const = &类::成员函数;
嵌套类:类里面还有类。
union:共用存储空间
union TockenValue
{
char cval;
int ival;
double dval;
}
//调用:
TockenValue myToken={'a'};
cout<<myTocken.cval<<endl;
局部类:类也可以在函数里,使用也只能在函数里。
位域
typedef unsigned int Bit;
class File
{
public:
Bit mode: 2;
Bit modified: 1;
Bit prot_owner: 3;
Bit prot_group: 3;
Bit peot_world: 3;
//...
}
enum {READ=01, WRITE=02};
int main()
{
File myFile;
myFile.mode = WRITE;
myFile.modified = 1;
}
volatile:防止变量过函数被优化,不要改变它的位置。
extern "C":使用C程序。
extern "C" void show(char *);