I know that the following snippet is valid:
template<typename T>
struct Custom
{
template<typename V> void func();
};
//valid
template<typename T>
template<typename V>
void Custom<T>::func()
{
}
But can we do the same for a class template instead of a member function template. Take for example,
template<typename T>
struct Custom
{ //declaration here
template<typename V> struct InnerCustom;
};
//can we define the class template `InnerCustom` outside?
template<typename T>
template<typename V>
Custom<T>::InnerCustom
{
};
My question is that can we have an out of class definition for the class template member InnerCustom
just like we had for the member function template func
? If so, how can i do that. Also, if not what is the reason for this difference.
Yes, you can make an out of class definition for InnerCustom
:
template <typename T>
template <typename V>
struct Custom<T>::InnerCustom { // note: `struct` added
// ...
};