Effective C++ ????
???????????? ???????[ 2012/12/7 10:45:29 ] ????????
??????const??inline??????#define
???????????ó????“??????????????????????”?????#define????????????????????????????????????????????????????
????#define ASPECT_RATIO 1.653
??????????????????????ASPECT_RATIO???????????????????????????????????????????????????ASPECT_RATIO????????????б??С?????漰?????????????????????????????????????????????????1.653????????ASPECT_RATIO?????ASPECT_RATIO???????????д???????ж???????????1.653?????????????????????????????????????????????????????У??????????????д????????????????????б??С?
??????????????????????????????????????????????
const double ASPECT_RATIO = 1.653;
???????????????Ч?????????????????????
??????????????????????е????????????????????????????У?????????????????????????????????????????const???????????????????????const?????磬????????ж??????????char*????????????????д????const??
const char * const authorName = "Scott Meyers";
????????const???????÷????????????????????????μ?????21??
?????????????????(class)???????????????????????????????????????У?????????????????????????????????????????????????????????????
class GamePlayer {
private:
static const int NUM_TURNS = 5; // constant eclaration
int scores[NUM_TURNS]; // use of constant
...
};
????????????????????????????????NUM_TURNS????????????????壬?????????????????????????ж?????????????????????????????????????????NUM_TURNS????????????????壬?????????????????????????ж?????????????
const int GamePlayer::NUM_TURNS; // mandatory definition;
// goes in class impl.file
??????????????????С??????????????壬??????????????
??????????????????????????????????????????????????????????????????????????????????????????????磺int?? bool?? char ?????????????????
?????????????????????????£??????????????????
class EngineeringConstants { // this goes in the class
private: // header file
static const double FUDGE_FACTOR;
...
};
// this goes in the class implementation file
const double EngineeringConstants::FUDGE_FACTOR = 1.35;
??????????????????????????????????????????????????????????????????????????GamePlayer::scores???????????????????б??????????????????С?????????????????Щ???????????????????????????????????????????????????ó???“????enum”?????????????????????????????????int???????????????????????????GamePlayer????????????????壺
class GamePlayer {
private:
enum { NUM_TURNS = 5 } // "the enum hack" — makes
// NUM_TURNS a symbolic name
// for 5
int scores[NUM_TURNS];// fine
};
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11