For the following code:
struct S
{
S() = default;
S(S const&) = default;
S(S&&) = default;
S& operator=(S const& other) = default;
S& operator=(S&&) = default;
template <typename... T>
S(T&&... params)
{
}
};
int main()
{
S s;
return 0;
}
I get an error message:
Error C2580 'S::S(void)': multiple versions of a defaulted special member functions are not allowed
Whic I don't understand. I think that the error is caused by the templated constructor (Verified this by commenting it out and got the program compiled).
template <typename... T>
S(T&&... params)
{
}
T can be empty leaving you with a default constructor, it can be S&&
leaving you with a move constructor, or it can be const S &
leaving you with a copy constructor.
But you just told the compiler you want the default version of those, so it's confused because you just gave it an explicit definition for each of those as well.
I would propose the following as a solution, since it's only the default constructor that is causing the problem, but this code crashes the compiler:
struct S
{
S() = default;
S(S const&) = default;
S(S&&) = default;
S& operator=(S const& other) = default;
S& operator=(S&&) = default;
template <typename S, typename... T>
S(S&& s, T&&... params)
{
}
};
int main()
{
S s;
return 0;
}