常量全局变量的模板

Template of constant global variable

本文关键字:全局变量 常量      更新时间:2023-10-16

这个模板定义使用MSVC是可以的,但不能在GNU上编译。问题出在哪里?编辑:我已经用C++11选项编译了它(使用mingw32)

#include <iostream>
using namespace std;
template <typename T>
const static size_t ALIGN_MASK = 64 / sizeof(T) - 1;    
int main() {
    // your code goes here
    cout << ALIGN_MASK<double>;
    return 0;
}
变量模板是C++14的一个特性。使用-std=c++14编译以使用此版本的标准。

如果这不起作用,您将不得不升级您的编译器。如果这不是一个选项,请使用具有static成员的struct