1
如果我有一個純虛函數的類,那麼所有函數都必須是純虛函數嗎?C++純虛函數
#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);
};
我試着運行了一個程序,它寫入messege:
Error 3 error LNK2001: unresolved external symbol "public: virtual void __thiscall Shape::input(void)" ([email protected]@@UAEXXZ)
Error 1 error LNK2001: unresolved external symbol "public: virtual void __thiscall Shape::print(void)" ([email protected]@@UAEXXZ)
不,但如果它不是純虛擬的,你需要爲它提供一個定義。 –
可能重複[什麼是未定義的引用/未解析的外部符號錯誤,以及如何解決它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external- symbol-error-and-how-do-i-fix) – dwcanillas
你應該閱讀這個錯誤,你會認識到:純虛函數沒有問題。 –