Explicit specialization of members of class templates

177 Views Asked by At

Trying to nail down the logic behind explicit specialization of members of class templates I composed this code below:

#include <iostream>
using namespace std;

template<class T> class X
{
    public:

    template<class U> class Y
    {
        public:
        template<class V> void f(U,V);
        void g(U);
    };
};

template<> template<> template<class V>
void X<int>::Y<int>::f(int, V) {}

int main() {
    X<int>::Y<int> b;
    b.f(1, 1);
}

It compiles without any problems. But when i introduce changes shown below, it refuses to compile at all:

#include <iostream>
using namespace std;

template<class T> class X
{
    public:

    template<class U> class Y
    {
        public:
        template<class V> void f(U,V);
        void g(U);
    };
};

template<> template<class U> template<class V>    // changes
void X<int>::Y<U>::f(U, V) {}               // changes

int main() {
    X<int>::Y<int> b;
    b.f(1, 1);
}

Error:

1>d:\projects\programs\youtube\lesson\lesson\main.cpp(17): error C3860: template argument list following class template name must list parameters in the order used in template parameter list 1>d:\projects\programs\youtube\lesson\lesson\main.cpp(17): error C3855: 'X': template parameter 'T' is incompatible with the declaration

Can somebody explain to me what is going on here? Thank you!

0

There are 0 best solutions below