I am reading The C++ Programming Language, 3rd Ed. book by Bjarne Stroustrup. It is really a nice book. However there are some parts that are unclear to me. It is about member constants that can be found at section 10.4.6.2 of the same book.
I will post the code here:
(1)
(2)
(3)
(4)
Now I know that there are comments but what I am looking for is the reason why those marked with errors does not work. I'd like to know why initialization of a const member variable in item 3 is not allowed if it is not static. The same type of questions is what I want to ask for items 4 and 5.
I tried to look it up at ISO/IEC 14882:1998(E) but since it was to long, I gave up looking. If there is anyone here could answer my questions above, please do help me and if you can, kindly point me to the section in 14882 or to any online reference.
Thanks!
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
I will post the code here:
Code:
class Curious {
public:
static const int c1 = 7 ; // ok, but remember definition
Code:
static int c2 = 11 ; // error: not const
Code:
const int c3 = 13 ; // error: not static
Code:
static const int c4 = f(7) ; // error: in-class initializer not constant
Code:
static const float c5 = 7.0 ; // error: in-class not integral[code] [b](5)[/b]
[code]} ;
Now I know that there are comments but what I am looking for is the reason why those marked with errors does not work. I'd like to know why initialization of a const member variable in item 3 is not allowed if it is not static. The same type of questions is what I want to ask for items 4 and 5.
I tried to look it up at ISO/IEC 14882:1998(E) but since it was to long, I gave up looking. If there is anyone here could answer my questions above, please do help me and if you can, kindly point me to the section in 14882 or to any online reference.
Thanks!
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -