C++.Coding.Standards.1918.Rules.Guidelines [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

C++.Coding.Standards.1918.Rules.Guidelines [Electronic resources] - نسخه متنی

Herb Sutter, Andrei Alexandrescu

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Discussion


Different kinds of classes serve different purposes, and so follow different rules. Value classes (e.g.,

std::pair, std::vector ) are modeled after built-in types. A value class:Item 35).

  • Is usually instantiated on the stack or as a directly held member of another class.


  • Base classes are the building blocks of class hierarchies. A base class:Item 50), and a nonpublic copy constructor and assignment operator (see Item 53).

  • Establishes interfaces through virtual functions.

  • Is usually instantiated dynamically on the heap and used via a (smart) pointer.


  • Loosely, traits classes are templates that carry information about types. A traits class:

    • Contains only

      typedef s and static functions. It has no modifiable state or virtuals.

    • Is not usually instantiated (construction can normally be disabled).


    Policy classes (normally templates) are fragments of pluggable behavior. A policy class:

    • May or may not have state or virtual functions.

    • Is not usually instantiated standalone, but only as a base or member.


    Exception classes exhibit an unusual mix of value and reference semantics: They are thrown by value but should be caught by reference (see Item 73). An exception class:Item 54) and visitation.

  • Preferably derives virtually from

    std::exception .


  • Ancillary classes typically support specific idioms (e.g., RAII; see Item 13). They should be easy to use correctly and hard to use incorrectly (e.g., see Item 53).


    / 521