I just want to ask why MSVS2013 complains with this code unlike GCC(4.8.3 at least):
template <typename T>
struct MyClass
{
typedef std::function<T*()> FunctionType;
static FunctionType funcObj;
};
template <typename T> typename MyClass<T>::FunctionType MyClass<T>::funcObj =
[]{return new T();};
In msvs2013, it complains this: Error 1 error C2061: syntax error : identifier 'T'
And to fix, i have to modify it to this:
template <typename T>
struct MyClass
{
typedef std::function<T*()> FunctionType;
static FunctionType funcObj;
static T* foo()
{
return new T();
}
};
template <typename T> typename MyClass<T>::FunctionType MyClass<T>::funcObj =
MyClass<T>::foo;
NOTE: 'MyClass < T > ::' is not necessary at the last line. I just want to imply that T is still usable on the right hand side of the operation(to be assigned), and when T was inside the lambda, it is not usable anymore.
Which one complies correctly in the current standard? Is there any way to ensure that the typename is still usable in a lambda in such cases?
Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire