C++ Terminology – 1. Variety of Types
Posted on January 23rd, 2006 at 11:05 by fr3@K

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 時, classstruct 幾乎是沒有差別且能互相替換 (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, 需符合下列條件:

  1. 沒有 user-defined constructor, destructor 以及 assignment operator
  2. 沒有 base class type, 換句話說非 derive 自 user-defined type
  3. 如果有 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.

del.icio.us:C++ Terminology - 1. Variety of Types digg:C++ Terminology - 1. Variety of Types spurl:C++ Terminology - 1. Variety of Types newsvine:C++ Terminology - 1. Variety of Types furl:C++ Terminology - 1. Variety of Types Y!:C++ Terminology - 1. Variety of Types 黑米共享書籤:C++ Terminology - 1. Variety of Types 推推王:C++ Terminology - 1. Variety of Types
Previous Post
« The Hungarian Notation «
Next Post
» C++ Terminology – 2. Instance and Instantiation »

Zero Comments »

No comments yet.

Comments RSS TrackBack URI

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>