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

Defining method with additional template parameters out of line

Given a templated class, how do I define a (further templated) method out of line? The syntax

template<class T> class C {
    public:
    template<class S> void f();
};

template<class S, class T> void C<T>::f<S>(){}

or any variant I have tried does not do the job:

error: use 'template' keyword to treat 'f' as a dependent template name
template<class S, class T> void C<T>::f<S>(){
                                      ^
                                      template
error: nested name specifier 'C<T>::' for declaration does not refer into a class, class template or class template partial specialization

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 :

You need to write two template headers:

template<class T>
template<class S>
void C<T>::f(){}
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