从抽象类派生一个类(C ++) [英] Deriving a class from an abstract class (C++)

查看:131
本文介绍了从抽象类派生一个类(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有纯虚函数f()的抽象类,我想创建一个从该类继承的类,并且还要重写函数f().我将头文件和cpp文件分开. 我在头文件中声明了函数f(int),定义在cpp文件中.但是,编译器说派生类仍然是抽象的. 我该如何解决?

I have an abstract class with a pure virtual function f() and i want to create a class inherited from that class, and also override function f(). I seperated the header file and the cpp file. I declared the function f(int) in the header file and the definition is in the cpp file. However, the compiler says the derived class is still abstract. How can i fix it?

推荐答案

函数f()和f(int)没有相同的签名,因此第二个函数不会为第一个提供实现. PVF的签名和实现必须完全匹配.

The functions f() and f(int) do not have the same signature, so the second would not provide an implementation for the first. The signatures of the PVF and the implementation must match exactly.

这篇关于从抽象类派生一个类(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆