1. 简化代码书写,尤其使用boost库,iterator或者指针等
typedef boost::filesystem::recursive_directory_iterator bf_rdit;
typedef char * PCHAR;// PCHAR p1, p2; // both p1 and p2 are pointer
2. 实现跨平台
#ifdef _WIN32 || WIN32
typedef __uint64 UINT64;
#else
typedef unsigned long long UINT64
#endif
typedef enum {SUCCESS, FAIL} ERET;
typedef struct {
char * data;
int length;
} Buffer;
typedef int (*BinaryOp)(int, int);
int g_Add(int lhs, int rhs)
{
return lhs + rhs;
}
// main function
{
BinaryOp pAdd = g_Add;
cout<<(*pAdd)(1,1)<<endl;
}
class CTestMath
{
public:
static int s_Add(int lhs, int rhs);
};
// main function
{
BinaryOp ps_Add = CTestMath::s_Add;
cout<<(*ps_Add)(1,1)<<endl;
}
class CTestMath
{
public:
CTestMath();
virtual ~CTestMath();
int m_Add(int lhs, int rhs);
protected:
private:
};
// main function
CTestMath *pinst = new CTestMath; // must
BinaryOp pm_Add = &CTestMath::m_Add;
cout<<(pinst->*pm_Add)(1,1)<<endl;
delete pinst;
typedef struct _Node
{
int data;
Node * Next;
} Node;
typedef struct _Node{
int data;
struct _Node * Next;
} Node;
typedef struct _Node Node, * PNode;
struct _Node{
int data;
PNode Next;
};
struct _Node{
int data;
struct _Node * Next;
};
typedef struct _Node Node, * PNode;
class Test
{
public:
typedef char Buf[256];
};
// main function
{
Test::Buf buf;
cout<<sizeof(buf)<<endl;// 256
}
typedef int (*a[5])(int, int);
typedef void (*b[10]) (void (*)());
//#define PCHAR char *;上述代码中如果PCHAR是使用define定义的,那实际函数需要的参数是const char *,而使用typedef将是char * const
typedef char * PCHAR;
int func(const PCHAR, const PCHAR);