#include <iostream>
using namespace std;
class NoConstructOperation
{
protected:
NoConstructOperation() = default;
virtual ~NoConstructOperation() = default;
public:
NoConstructOperation(const NoConstructOperation&) = delete;
NoConstructOperation& operator =(NoConstructOperation&) = delete;
NoConstructOperation(NoConstructOperation&&) = delete;
NoConstructOperation& operator = (NoConstructOperation&&) = delete;
};
class Myclass:public NoConstructOperation
{
};
int main() {
static_assert(!std::is_trivially_destructible<Myclass>::value, "Compiler provided destructor is public: Please declare it private");
return 0;
}
工作,如果我不NoConstructOperation
上面的代碼繼承Myclass
給人以靜態斷言編譯錯誤。
但如果我繼承Myclass
與NoConstructOperation
is_trivially_destructible
檢查不起作用,即使Myclass
構造函數是公共的。此代碼編譯,是什麼原因?`is_trivially_destructible`不繼承類
你想用這個做什麼? – Hayt