如果我有一个只有一个纯虚函数的类,那么所有的函数都必须是纯虚函数吗?
#pragma once
class Shape {
private:
static int countShape;
public:
virtual float perimeter() const=0;
virtual float area() const=0;
virtual void print();
virtual void input();
void setCountShape();
int getCountShape()const{return countShape;};
Shape(void);
~Shape(void);
};我试着运行我的程序,它写下这样的消息:
Error 3 error LNK2001: unresolved external symbol "public: virtual void __thiscall Shape::input(void)" (?input@Shape@@UAEXXZ)
Error 1 error LNK2001: unresolved external symbol "public: virtual void __thiscall Shape::print(void)" (?print@Shape@@UAEXXZ)发布于 2015-05-21 02:23:04
要回答你问的具体问题:不。仅仅因为你有一个纯虚函数,并不意味着其他函数也必须是纯虚函数。该类可以有任意数量的纯虚函数、“常规”虚函数、非虚成员函数和静态成员函数。
尽管如其他人所指出的,你得到的错误与虚函数无关。
发布于 2015-05-21 02:14:34
除非将虚函数标记为纯虚函数,否则需要实现虚函数。
如果一个类包含多个纯虚函数,那么它就是抽象的;它不能被实例化。
https://stackoverflow.com/questions/30357356
复制相似问题