no matching function to call to “standard constructor”

前端 未结 4 1020
醉梦人生
醉梦人生 2021-01-20 04:27

I get a weird response from my c++ compiler. I searched the internet but came up with nothing usefull or helpfull...

Compiler Response:

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 05:13

    floating.hpp|line 29|warning: `class HexFloatingPoint' has virtual functions but non-virtual destructor

    Add a virtual destructor to the HexFloatingPoint:

    virtual ~HexFloatingPoint(); 
    

    As soon as a class has virtual functions, you need to declare/define a virtual destructor, otherwise if you access the derived class through a base class pointer or a reference in your client code, it may happen that the destructor of the derived class doesn't get called, the behaviour is undefined. Usually, the derived part of the object is not deleted (access via base reference or pointer) in which case, you are left with a memory leak. Check out Effective C++, item 7.

    floating.hpp|line 29|warning: `class HexFloatingPoint' has virtual functions but non-virtual destructor

    As soon as you define a constructor for a class, the default constructor HexFloatingPoint() is not defined automatically, you need to explicitly add it to the class declaration/definition.

提交回复
热议问题