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

VS2019 explicit specialization requires template<> error with 'using' keyword

I have this piece of c++ code, and VS2019 to compile it:

#include <iostream>
template<typename t>
class c
{

};

int main(){
    using o = class c<int>;
}

does anybody know why it does not compile, complaining about:

Error   C2906   'c<int>': explicit specialization requires 'template <>'

With mingw-gcc it compiles and runs without error.

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

Here you can compare compiler outputs: https://godbolt.org/z/55fMzh8qz

Thanks in advance.

>Solution :

class is unnecessary in the using statement, I think visual studio thinks you are trying to declare a specialisation of c:

template <>
class c<int>;

hence the error message.

All you need is:

using o = c<int>;
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