![](/img/trans.png)
[英]Visual Studio 2015: Extern "C" and the "export" keyword
[英]Visual Studio C2580 when using default keyword
對於以下代碼:
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;
}
我收到一條錯誤消息:
錯誤 C2580“S::S(void)”:不允許使用多個版本的默認特殊成員函數
我不明白。 我認為該錯誤是由模板化構造函數引起的(通過將其注釋掉並編譯程序來驗證這一點)。
template <typename... T>
S(T&&... params)
{
}
T 可以是空的,給你一個默認的構造函數,它可以是S&&
給你一個移動構造函數,或者它可以是const S &
給你一個復制構造函數。
但是你只是告訴編譯器你想要這些的默認版本,所以它很困惑,因為你只是給了它一個明確的定義。
我會提出以下作為解決方案,因為它只是導致問題的默認構造函數,但此代碼使編譯器崩潰:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.