1

If I have a class with one pure virtual function, must all the functions be pure virtual as well?

#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);
};

I tried to run my program and it writes the messege:

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)
frb
  • 3,738
  • 2
  • 21
  • 51
user3590450
  • 463
  • 1
  • 6
  • 13
  • 1
    No, but if it's not pure virtual you need to provide a definition for it. – T.C. May 20 '15 at 18:14
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – dwcanillas May 20 '15 at 18:14
  • You should read the error and you would recognize: The pure virtual functions are no issue. –  May 20 '15 at 18:16

2 Answers2

1

To answer the specific question you asked: No. Just because you have one pure virtual function, that doesn't mean that any other functions have to be pure virtual as well. The class can have any number of pure virtual, "regular" virtual, non-virtual, and static member functions.

Although, as others have pointed out, the error you're getting has nothing to do with the function being virtual.

Dan Korn
  • 1,274
  • 9
  • 14
0

You need to implement the virtual functions unless you mark them as pure virtual.

If a class contains one more more pure virtual functions then it is abstract; it cannot be instantiated.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483