【发布时间】:2021-02-20 13:23:09
【问题描述】:
为什么这不起作用:
#include <cstring>
template<size_t sz>
struct wstr {
wchar_t _str[sz];
wstr(const wchar_t source[sz]) {
wcscpy_s(_str, source);
}
};
int main(int argc, char** argv) {
wstr ws = L"Hello"; //needs template argument
return 0;
}
L"Hello" 已知是const wchar_t[6]。
【问题讨论】:
-
source的类型是wchar_t const *,而不是数组,即使它被声明为一个。
标签: c++ arrays template-argument-deduction