Topic: member initialization in class declaration


Author: Bret Pehrson <bretp@strata3d.com>
Date: 1996/06/07
Raw View
I remeber reading in either the ARM or the Design and Evolution of C++ why Bjarne did
not allow member variable initialization in the class declaration, but I've since
forgot and can't find the reason.  If anyone remembers, or has futher knowledge on
the topic, please post a follow-up.

tnx.
--
Bret Pehrson        BretP@strata3d.com
*Please respond to newsgroup unless specified otherwise
--


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: clamage@Eng (Steve Clamage)
Date: 1996/06/07
Raw View
In article 4CEF@strata3d.com, Bret Pehrson <bretp@strata3d.com> writes:
>I remeber reading in either the ARM or the Design and Evolution of C++ why Bjarne did
>not allow member variable initialization in the class declaration, but I've since
>forgot and can't find the reason.  If anyone remembers, or has futher knowledge on
>the topic, please post a follow-up.

Assuming you mean static data members, it would amount to allowing multiple
definitions of the same object, due to having the definition in multiple
translation units. Just as that is not allowed for ordinary variables, it is
not allowed for class members, with one new exception.

For const static data of integral type, the language rules were recently
extended to allow initialization in the class definition:
 class A {
  static const int size = 100;
  char buf[size];
  ...
 };
Previously, there was no nice way to get this effect. You still must provide
exactly one definition of A::size in one translation unit, but WITHOUT an
initializer:
 const int A::size;
---
Steve Clamage, stephen.clamage@eng.sun.com