[英]How can I default initialize static class template variables
In the following code 在下面的代码中
#include <iostream>
#include <string>
#include <type_traits>
template<class T, typename = std::enable_if<std::is_default_constructible<T>::value>>
struct E {
static T var;
};
int main() {
std::cout << E<std::string>::var << std::endl;
}
How can I have E<T>::var
default constructed for each template instantiation of E
? 如何为E
每个模板实例构造E<T>::var
默认值? Currently I receiev linker error 目前我收到链接器错误
/home/tE1MjB/ccEXSZtn.o: In function `main':
prog.cpp:(.text.startup+0x12): undefined reference to `E<std::string, std::enable_if<true, void> >::var'
collect2: error: ld returned 1 exit status
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.