Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can we have an out of class definition for a class template that is a member of a class template

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, you can make an out of class definition for InnerCustom:

template <typename T>
template <typename V>
struct Custom<T>::InnerCustom { // note: `struct` added
    // ...
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading