难道是GCC巨大的BUG,模板类的静态成员无法调用构造函数?
A为模板类,其中有一个静态成员s类型为B。GCC编译、运行都成功,但是无法调用B的构造函数。
而静态变量s1却可以正常的初始化。
为什么对象的构造函数不能执行呢?
#include <iostream>
#include "h.h"
int main()
{
A<string> objA(111);
}
h.h:
****************************************************
#ifndef POOL_H_INCLUDED_GF
#define POOL_H_INCLUDED_GF
#include <iostream>
#include "s.h"
using namespace std;
template <typename T>
class A
{
public:
int a1;
A(int a1)
{
this->a1=a1;
cout<<"init A"<<endl;
cout<<"sizeof T ="<<sizeof(T)<<endl;
cout<<"s1="<<A::s1<<endl;
}
static int s1;
static B s;
};
template <typename T> int A<T>::s1=1234;
template <typename T> B A<T>::s;
#endif
s.h
*****************************************************
#ifndef SH
#define SH
#include <iostream>
using namespace std;
class B
{
public:
int m1;
B()
{
cout<<"init static 0"<<endl;
}
};
#endif