* shellux:
You can default-initialize it (perhaps with C++2003 that is
value-initialize, but it's the same thing for this problem) with
> A():m_b() {}
Otherwise you'll have to call a function that does the initialization,
or do it directly in the constructor body.
I have test a similar class as follow(in VC6.0) , but, as the
consequence, linker offer an error.
class Te {
public:
Te() : m_int() {
}
private:
const int m_int[10];
};
Linker:d:\program_production\c++\visual_c++\practi ce\commutytry\communitytry.cpp(3)
: error C2439: 'm_int' : member could not be initialized
d:\program_production\c++\visual_c++\practice\comm utytry\communitytry.cpp(7)
: see declaration of 'm_int'
Please be accurate in your reporting: you don't have a linker error but
a compilation error, and it looks to me as if you're using version 8.0,
not version 6.0.
That said, Visual C++ 6.0 is not the most standard-conforming compiler
in the world. Version 7.1 is much better (and 8.0 better still).
However, I tried your code with version 7.1, and the compiler failed;
for non-const it didn't issue an erronous diagnostic, but generated
incorrect non-initializing machine code.
It seems that g++ handles this correctly, and of course, Comeau does.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?