On Nov 3, 10:15*pm, sean_in_rale...@yahoo.com wrote:
On Nov 3, 3:34 pm, Chameleon <cham_...@hotmail.comwrote:
The following code produces strange errors in mingw. Is a
C++ problem or compiler problem?
Your problem. The code is not legal C++.
----------------------------
#include <list>
class A
{
* * static const int B = 0;
Sadly, the above line does not define storage for B, but only
declares it.
You also need this defined somewhere:
* const int A::B;
I believe it's just working for you in the second case because
it's getting optimized away. *Compiler bug, I guess.
No compiler bug. Not defining a variable which has been used is
undefined behavior, so anything the compiler does with it is
fine. In practice, given a declaration which can be used as an
integral constant expression, most compilers will only require
the definition if it is used in a context where there was not an
immediate lvalue to rvalue conversion. When you use it to
initialize another int, there is an immediate lvalue to rvalue
conversion; list<int>::push_back, on the other hand, takes a
reference, so there is no lvalue to rvalue conversion.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34