Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2001-05-02 07:54:52


From: "Peter Schmitteckert (boost)" <boost_at_[hidden]>
> I have one question:
> My g++ v2.95.4 (and 2.95.3) allows static const members to be
initialized in
> the the class declaration:
>
> template< typename F> class Q
> {
> public:
> static const F zz = 17;
> }
>
> and it works fine. Is this a g++ extension?

You can ask g++, and it will tell you. Run this program through it:

template< typename F> class Q {
  public:
      static const F zz = 17;
};
Q<float> q;
int main() {}

and invoke g++ like this:
g++ -Wall -pedantic test.cpp

The result is:
test.cpp: In instantiation of `Q<float>':
test.cpp:5: instantiated from here
test.cpp:3: warning: ANSI C++ forbids initialization of member constant
`Q<float>::zz' of non-integral type `const float'

So the answer is yes, it is a g++ extension. ANSI C++ only supports
initializing integers inline. When F is a floating-point type, the code
needs the g++ extension to work.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk