C++Builder 10.4.2
我创建了一个具有纯虚拟函数的TFrame。然后从该TFrame派生出另一个虚函数,但没有覆盖基类虚函数。
我希望得到编译器错误,但没有。
该行为是否未在VCL类中实现?
这是代码:
// create a frame from File/New..., add a pure virtual function
class TFrame4 : public TFrame
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TFrame4(TComponent* Owner);
virtual void func() = 0;
};
extern PACKAGE TFrame4 *Frame4;
// derive a frame from it, put it on the main form. compile/run
without error
class TFrame5 : public TFrame4
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TFrame5(TComponent* Owner);
};
extern PACKAGE TFrame5 *Frame5;发布于 2021-09-06 09:14:18
这是因为TFrame是由VCL框架创建的,该框架是用Delphi语言编写的。因此对象永远不会遇到新的‘C++’关键字。
尝试创建一个“虚拟”对象,隔离在一个单独的名称空间中。这个对象永远不会真正被创建,但它足以触发C++编译器测试抽象类的具体用法。
例如:
namespace Test {
// this will never really created
new TFrame5( nullptr ); // <- should trigger an error
}另请参阅:
https://quality.embarcadero.com/browse/RSP-28329
问候
https://stackoverflow.com/questions/69059445
复制相似问题