我已经在派生类中实现了纯虚拟方法,但编译器抱怨我没有
I have implemented the pure virtual method in the derived class but the compiler complains that I didn't
我有一个抽象基类及其派生类,尽管我在派生类的 cpp 文件中实现了纯函数,但当我尝试创建派生的对象时,我仍然收到一个错误,说派生类是一个抽象的!!基础:
class Base {
protected:
string name;
int quantity;
double price;
public:
c'tor....
virtual ~Base(){}
virtual void buy(int num) = 0;
virtual Base& operator+(const Base& b)=0;
};
派生:
#include "Base.h"
class Derived : public Base{
protected:
double percentage;
public:
c'tor...
virtual ~Derived() {}
virtual void buy(int num);
virtual Derived& operator+(const Derived& d);
};
派生.cpp:
#include "Derived.h"
void Derived::buy(int num){
//implementation
}
Derived& Derived::operator+(const Derived& d){
//implemetation
}
主.cpp:
#include "Base.h"
#include "Derived.h"
int main() {
Derived d;
//...
}
错误:
1 IntelliSense: object of abstract class type "Derived" is not allowed:
pure virtual function "Base::buy" has no overrider c:UsersaubDocumentsVisual Studio 2013ProjectsProject22Project22main.cpp 10
您有一些构建问题。可能是链接了派生对象文件的过时版本?还是派生.cpp根本没有被编译并链接到项目中?
从头开始进行全新重建。
相关文章:
- 重载方法的方式会在使用临时调用时生成编译器错误
- 处理编译器关于可能丢失数据的警告的最优雅方法是什么
- 编译器无法识别在类声明之外定义的方法
- 让编译器告诉什么确切的纯虚拟方法使结构抽象?
- 我可以让编译器忽略特定于操作系统的方法吗?
- Qt中的包装连接方法隐藏了编译器所需的信息
- G++ 编译器未为未定义的方法生成错误/警告
- 从 int 中剥离位时,编译器会警告一个转换,但不警告其他转换.有解决方法吗?
- 如果方法在类中定义,则阻止编译器删除方法
- 虚拟基类在内部如何工作?编译器如何解析对基方法的调用?
- CMake + Qt,moc 编译失败,无法实现 QMetaObject 方法(编译器找不到基本 ui 对象的标头?
- Visual Studio 2015资源视图和资源编译器使用不同的方法在项目目录中查找图标文件.如何修复
- C++编译器何时推断 no,除了方法?
- 对列表类中的泛型方法禁用编译器警告 2100,该泛型方法可能包含指针,也可能不包含指针
- 为什么编译器找不到超类的方法?
- 如何让编译器在C++中更喜欢常量方法重载?
- 无法通过可变参数函数将函数指针传递给父类中的方法--编译器错误?
- 没有匹配的方法编译器错误
- 调用继承方法-编译器错误
- 无法调用派生类的方法 - 编译器将对象实例标识为基类