T
Terence
Hi,
I created the following two files for testing:
// begin test.h
#include <list>
class E {};
struct L {};
template <class T> struct A {
static std::list<A<T> *> alist;
A() {}
A(const E &) { alist.push_back(this); }
};
struct B : public A<L>{
B(const E &e) : A<L>(e) {}
};
// end test.h
and:
// begin test.cpp
#include <iostream>
#include "test.h"
using namespace std;
template <class T> std::list<A<T> *> A<T>::alist;
template class A<L>;
static B *b_ex = new B(E());
int main() {
cout << A<L>::alist.size() << endl;
return 0;
}
// end test.cpp
Now, after compiling without errors or warnings, on execution I get a
segmentation fault concerning insertion in the list.
How could this problem be resolved, most genericly?
Thanks for all hints,
Terence
I created the following two files for testing:
// begin test.h
#include <list>
class E {};
struct L {};
template <class T> struct A {
static std::list<A<T> *> alist;
A() {}
A(const E &) { alist.push_back(this); }
};
struct B : public A<L>{
B(const E &e) : A<L>(e) {}
};
// end test.h
and:
// begin test.cpp
#include <iostream>
#include "test.h"
using namespace std;
template <class T> std::list<A<T> *> A<T>::alist;
template class A<L>;
static B *b_ex = new B(E());
int main() {
cout << A<L>::alist.size() << endl;
return 0;
}
// end test.cpp
Now, after compiling without errors or warnings, on execution I get a
segmentation fault concerning insertion in the list.
How could this problem be resolved, most genericly?
Thanks for all hints,
Terence