您的位置:首页 > 编程语言 > C语言/C++

Effective C++ 18. Make interfaces easy to use correctly and hard to use incorrectly

2017-10-26 16:41 537 查看
Class Month {
public:
explicit Month() {
month = m;
}
private:
int month;
};

Month Jan(Month(1));


// in other file
extern Month Jan;
Data d(Jan, Day(30), Year(1995));   // wrong! unless Jan is initialized before d defined


class Month {
public:
static Month Jan() { return Month(1); }
private:
explicit Month(int m);
};
Date d(Month::Jan(), Day(30), Year(1995));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐