我正在http://sourceforge.net/projects/dtmf/研究 DTMF 代码。我遇到了一些我无法理解的 C++ 代码:
template<int, int, int, int> class Types;
template <> class Types<5, 4, 2, 1>
{
public:
typedef long int Int40;
typedef unsigned long int Uint40;
typedef int Int32;
typedef unsigned int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
typedef char Int8;
typedef unsigned char Uint8;
};
template <> class Types<8, 4, 2, 1>
{
public:
typedef long int Int64;
typedef unsigned long int Uint64;
typedef int Int32;
typedef unsigned int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
typedef char Int8;
typedef unsigned char Uint8;
};
template <> class Types<4, 4, 2, 1>
{
public:
typedef int Int32;
typedef unsigned int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
typedef char Int8;
typedef unsigned char Uint8;
};
// For 16bit chars
template <> class Types<2, 1, 1, 1>
{
public:
typedef long int Int32;
typedef unsigned long int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
};
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Int32 INT32;
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Uint32 UINT32;
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Int16 INT16;
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Uint16 UINT16;
从那里开始,它们就像普通的原始类型一样使用:
static const INT16 tempCoeff[8];
我的直觉告诉我,所有这些东西都实现了某种跨平台可移植性。我是对的,还是还有更多?