关闭

static data in c++ class

641人阅读 评论(0) 收藏 举报
分类:

e:\books\2013\c++\C++.Primer.Plus.6th.Edition.pdf

 

C++ has a second way of defining a constant within a class—using the keyword static:
class Bakery
{
private:
static const int Months = 12;
double costs[Months];
...
This creates a single constant called Months that is stored with other static variables
rather than in an object.Thus, there is only one Months constant shared by all Bakery
objects. Chapter 12 looks further into static class members. In C++98 you can use this
technique only for declaring static constants with integral and enumeration values.Thus,
C++98 doesn’t allow you to store a double constant this way. C++11 removes that
restriction.

chapter 12

A Review Example and Static Class Members

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:308973次
    • 积分:4905
    • 等级:
    • 排名:第6000名
    • 原创:185篇
    • 转载:41篇
    • 译文:0篇
    • 评论:52条
    文章分类
    最新评论