- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力清除一些在使用提升警告时同时出现在 GCC 和 MSVC 上的警告。我在 MSVC 下遇到 “类具有虚函数,但析构函数不是此类的虚实例可能无法正确销毁”。当启用适当的警告时,我在 GCC 和 Clang 下收到类似的警告。我正在尝试了解投诉内容。
有问题的类没有析构函数(虚拟的或其他的;由人类编写)。它的基类也是如此。该类有堆栈分配的成员对象,但没有分配new
。该类是一个模板
。最后,有时,层次结构中的类被标记为“无 vtable”(但这不是这种情况)。
如果我添加一个空的虚拟析构函数,则警告被清除。但鉴于上述一些限制,我想确保我没有遗漏一些不明显的东西。
以下是我遇到的与编译器相关的问题和警告:
如果上面的答案实际上是“我需要学习使用我的工具”,那么我很乐意提供空的 dtor 来使用分析工具。 (我认为声称这些工具不如程序员聪明是非常虚伪的,所以禁用它们。坏人可能一路笑到银行,摘下开发人员不会被打扰的低垂果实......) .
这是被警告标记的类之一。
template <class T>
class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation<T>
{
public:
typedef T Element;
DL_FixedBasePrecomputationImpl() : m_windowSize(0) {}
// DL_FixedBasePrecomputation
bool IsInitialized() const
{return !m_bases.empty();}
void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base);
const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const
{return group.NeedConversions() ? m_base : m_bases[0];}
void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage);
void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation);
void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const;
Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const;
private:
void PrepareCascade(const DL_GroupPrecomputation<Element> &group, std::vector<BaseAndExponent<Element> > &eb, const Integer &exponent) const;
Element m_base;
unsigned int m_windowSize;
Integer m_exponentBase; // what base to represent the exponent in
std::vector<Element> m_bases; // precalculated bases
};
下面是一些相关的问题:
最佳答案
The class in question has no destructor (virtual or otherwise).
有趣的事实:C++ 中的所有对象都有一个析构函数。很简单,如果你不定义一个,编译器会生成它,对于原语,这是一个空操作。
Why is the compiler generated destructor not virtual?
因为人们提示如果每个 C++ 程序中的每个类都有一个虚拟析构函数,将会对他们的性能产生不利影响。
Why is the compiler generated destructor not sufficient?
它完全足够 - 用于销毁它为其生成的类。销毁它的派生类(如果有的话)是它不应该达到的目的。
What is the difference between an empty dtor provided by me and a default dtor provided by the compiler?
如果您没有将其定义为 virtual
,那么空的 dtor 将禁止优化(有时),仅此而已。否则,区别很明显——你的是 virtual
(另外)。一些模板可能要求您的类是微不足道的可破坏的,但这并不常见。
Does templates affect what the compiler can generate?
没有。
Does "no vtable" affect what the compiler can generate?
没有。
关于c++ - 编译器在 GCC 和 MSVC 中生成析构函数和警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31111605/
我是一名优秀的程序员,十分优秀!