[英]How can I Declare/define/initialize a static member variable of template classes as static member variables of a class?
[英]How can I default initialize static class template variables
在下面的代碼中
#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;
}
如何為E
每個模板實例構造E<T>::var
默認值? 目前我收到鏈接器錯誤
/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.