This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Sequence matters! GCC bug?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Sequence matters! GCC bug?
- From: Yu Qian Zhou <Yu dot Qian dot Zhou at comlab dot ox dot ac dot uk>
- Date: Fri, 30 Mar 2001 21:45:02 +0100 (BST)
- Newsgroups: comp.lang.c++
(Static members of the base class should always be inititialed first by
the *compiler*! -- not by the *programmer* on command-line -- I hope.)
$ g++ b.cpp a.cpp main.cpp -o main
$ ./main
$
$ g++ a.cpp b.cpp main.cpp -o main
$ ./main
Segmentation fault (core dumped)
$
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
$
Here is the files:
--- File: a.h -------------------------------------------------------------
#ifndef A_H
#define A_H
class A{
public: static int* a;
};
#endif
---------------------------------------------------------------------------
--- File: a.cpp -----------------------------------------------------------
#include "a.h"
int* A::a = new int[3];
---------------------------------------------------------------------------
--- File: b.h -------------------------------------------------------------
#ifndef B_H
#define B_H
#include "a.h"
class B: public A{
public:
static int b;
};
#endif
---------------------------------------------------------------------------
--- File: a.cpp -----------------------------------------------------------
#include "b.h"
int B::b = B::a[0];
---------------------------------------------------------------------------
--- File: main.cpp --------------------------------------------------------
#include "a.h"
#include "b.h"
int main()
{
B* b;
b = new B();
return 0;
}
---------------------------------------------------------------------------