Advertisement

error C2955 "use of class template requires template argument list" with C++17 Standards when default template parameter is provided

Started by September 17, 2024 02:25 AM
5 comments, last by Juliean 2 months, 4 weeks ago

I have a project which compiled well years ago,but when I compiled it recently,it gives me the error "use of class template requires template argument list",the code line causes this error is:

wfs_Vec3        m_vCenterSpeed;

The template wfs_Vec3 is provided with default template parameter as follow:

template<typename T = float>
struct wfs_Vec3
{
...
};

My compiler is visual studio 2019 community,I have tried to change C++ Language option to C++17 and C++20,and this error still persists,the odd is when I created a new project and tested this line:

wfs_Vec3        m_vCenterSpeed;

It's all fine and compiled with no error.I didn't change the code since its compiled well years ago,all I can think of is I have updated my visual studio, I absolutely have no clue,can anyone help me?

I think you have two options here:

//Option 1
wfs_Vec3<> MyVec3;

//Option 2
using Vec3F = wfs_Vec3<float>;
Vec3F MyVec3F;
Advertisement

@Aerodactyl55 I already go with Option 1,because I think the problem is related to compiler,and option 1 is acceptable for me,thanks.

Your original code is not valid C++. You have to specify the <> even if the argument has a default parameter. MSVC might accept it under certain circumstances, as their compiler often is not very conformant to the C++-standard. You might look into the “/permissive” flag, as this is the only thing that I could imagine would change this. Though I certainly remember getting compile errors for forgetting the <> on default-parametered classes even in VS2013, so there must be probably something else going on that made the code originally compile, like an intermediate typedef or whatever.

I think you are wrong,it's valid after c++17,see here

https://stackoverflow.com/a/50970942/539997

Ah, you are actually correct, class template argument deduction makes this code possible. It does compile on locally on my Visual Studio 2022, but only with C++17. C++14 or below gives the error you are getting. Odd. Did you make sure that in your project, you change the C++-version switch for the current project-configuration? Options might show a target that you don't have active. Otherwise, it might be something related to VS2019, which I cannot really test since I don't have it installed anymore.

This topic is closed to new replies.

Advertisement