[CSI] final topics
Mikhail Nesterenko
mikhail at cs.kent.edu
Thu Aug 18 13:32:16 EDT 2016
>
> What is a static constant? In particular, what is the difference between the use of static const and const, as in:
>
> class Date {
> public:
> ...
> private:
> static const int cent21 = 2001;
> ...
> };
>
> and this:
>
> class Date {
> public:
> ...
> private:
> const int cent21 = 2001;
> ...
> };
>
A static constant is shared by all objects of the class while
(non)-static constant may potentially be different for different
objects. For example, a constant my be initialized with the
initializer list. Consider the following class:
class Date{
public:
Date(int c): cent21(c) {}
private:
const int cent21;
};
The objects for this class may be declared as follows:
Date d1(55), d2(66);
The two objects would have cent21 intialized to different values.
Thanks,
--
Mikhail
More information about the cs13001
mailing list