![](/img/trans.png)
[英]Does Visual Studio 2013 CTP support in-class static const initializers for non-integral types?
[英]in-class initialization of non-integral static data
因此,我剛剛通過編譯器錯誤得知,數組的類內初始化無效(為什么?)。 現在,我想在模板類中初始化一些數組,但是不幸的是,內容取決於template參數。 壓縮的測試用例如下所示:
template<typename T>
struct A {
T x;
static const int len = sizeof(T); // this is of course fine
static const int table[4] = { 0, len, 2*len, 3*len }; //this not
}
任何想法如何拉出常量數組?
編輯:添加了'int's。
就像沒有模板時一樣; 將初始化放在類的聲明之外:
template<class T>
const int A<T>::table[4] = { 0, len, 2*len, 3*len };
template <typename T, int index>
struct Table {
static const len = sizeof(T);
static const value = len*index;
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.