samedi 22 septembre 2018

Visual C++ error with friend template class in C++11

I have a piece of code which works with g++/clang++. It has recently been reported to me that it breaks with Visual C++.

The code is this:

namespace q {
    template <typename X, typename Y>
    struct A {};
}

template <typename X>
struct B {
    template <typename Y>
    friend struct q::A;
};

int main() {
    return 0;
}

VC++ returns the following error:

source_file.cpp(9): error C2976: 'q::A': too few template arguments
source_file.cpp(3): note: see declaration of 'q::A'
source_file.cpp(10): note: see reference to class template instantiation 'B<X>' being compiled

Who is correct? Is there a portable way to do this?

Aucun commentaire:

Enregistrer un commentaire