常量全局变量的模板
Template of constant global variable
这个模板定义使用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;
}
-std=c++14
编译以使用此版本的标准。
如果这不起作用,您将不得不升级您的编译器。如果这不是一个选项,请使用具有static
成员的struct
。
相关文章:
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 当vector是tje全局变量时,c++中vector的内存管理
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 内联函数中具有内部链接的全局变量
- 如何在信号处理程序和普通函数中对全局变量进行互斥读写操作
- 全局变量 多读取器 一个写入器多线程安全?
- 如果全局变量默认是外部变量,为什么要添加"extern"关键字?
- 不同作用域中的静态变量和全局变量
- 对全局变量的非常量引用的初始化无效
- 全局变量中的静态常量与常量
- C++ 给出编译器错误,将一个(静态)常量全局变量设置为另一个静态常量变量
- 将全局变量作为常量引用传递
- 类使用全局外部常量变量,该变量通过内部链接定义
- 静态、常量和全局变量带来的性能提升
- 常量全局变量的模板
- 类作为cli c++中全局非常量变量的库
- 全局变量/常量的替代方案
- 命名空间中的常量全局变量
- 为什么C++中允许常量全局变量的多重定义,而C中不允许
- 从命令行读取常量作为全局变量