Fundamental Type
Aka. built-in type, primitive type, native type and etc. C++ core language 原生支援型別. 包含pointer, reference 以及用 const 或 volatile 修飾過的型別 (不包含 C++ Standard Library 定義的型別!), e.g.:
- float
- volatile unsigned int
- const char*
- double&
Integral Type
為 fundamental type 的 subset. 代表整數的 fundamental type, e.g.:
- char
- unsigned short
- long
User-defined Type
Aka. class type. 使用者自訂型別, 也稱為類或類別. 泛指所有的 struct 與 class, 包含 C++ Standard Library 定義的型別, e.g.:
class SomeClass;
struct SomeStruct;
template class basic_string;
對 C++ 來說, 在定義 user-defined type 時, class 與 struct 幾乎是沒有差別且能互相替換 (interchangable). 唯一的差別是預設 (默認) 的存取權限:
class DerivedClass : /*private*/ BaseClass
{
/*private:*/
int data;
};
struct DerivedStruct : /*public*/ BaseStruct
{
/*public:*/
int data;
};
POD
Acronym for Plain Old Data. User-defined C-style structure. 為 user-defined type 的 subset, 需符合下列條件:
- 沒有 user-defined constructor, destructor 以及 assignment operator
- 沒有 base class type, 換句話說非 derive 自 user-defined type
- 如果有 data member, 其所有 data member 必須為 fundamental type 或 POD
下兩例皆為 POD:
class SomePodType
{
public:
unsigned int data0;
};
struct AnotherPodTypeWithDataMember
{
SomePodType data1;
char data2;
};
Template Class
也是 user-defined type 的 subset. 為 class template 的 instance (具現), e.g.:
typedef list<char> IntList;
上例中 list; 為 class template, IntList 為 template class.
Type
泛指任何 fundamental type 或 user-defined type.
