Here is the code,
#include<iostream>
using namespace std;
template <typename T>
class TestClass {
T value;
enum _SyncType {
SYNC_TYPE,
ASYNC_TYPE,
};
static const char *const kSyncString[];
};
template <typename T>
const char *const TestClass<T>::kSyncString[] = {
[TestClass<T>::SYNC_TYPE] = "sync type",
[TestClass<T>::ASYNC_TYPE] = "async type",
};
int main() {
TestClass<int> test;
return 0;
}
When I compile it, it reminds
prog.cpp:19:1: error: the value of 'SYNC_TYPE' is not usable in a constant expression
};
^
prog.cpp:8:5: note: 'TestClass<T>::_SyncType SYNC_TYPE' is not const
SYNC_TYPE,
^
prog.cpp:19: confused by earlier errors, bailing out
I think maybe the template doesn't have any instance yet, but how should I write such code?