作者:深圳教育在线 来源:www.szedu.net 更新日期:2010-3-18
c++中typedef类型定义的用法,typedef,为"类型定义",可以解释为:将一种数据类型定义为某一个标识符,在程序中使用该标识符来实现相应数据类型变量的定义。
总结一下,常用之处
1: 定义函数指针
#include "stdafx.h"
#include
#include
using namespace std;
typedef void (*F)(int);
void print1(int x){
cout<
}
int main(){
F a;
a = print1;
(*a)(20);
}
2:简单类型替换:
#include "stdafx.h"
#include
#include
using namespace std;
typedef int I;
int main(){
I a;
a = 10;
//a = "a";//false
cout<
}
3:定义数组类型:
#include "stdafx.h"
#include
#include
using namespace std;
typedef int A[3];
int main(){
A b = {3,4,5};
cout<
}
|