-5
我使用純虛擬方法,如下面的代碼所示。爲什麼這種純虛擬方法不能編譯?
#include <iostream>
using namespace std;
class Advertisment
{
public:
vitual void price (int Uchrg, int no_of_unt) = 0;
{
}
};
class TVadvertisment : public Advertisment
{
public:
void price (int Uchrg, int no_of_unt)
{
int adPrice = Uchrg * no_of_unt;
cout << "Advertisment Price: " << adPrice;
}
};
int main()
{
TVadvertisment T;
T.price(1000, 60);
return 0;
}
因爲我知道純虛函數將被聲明爲virtual void display() = 0;
。但是Code :: Blocks編譯器由於此= 0
而顯示錯誤。沒有它,它會成功編譯。
而且我也沒有使用指針來調用派生類的方法。
請編輯您的問題,在問題本身中提供[mcve] *。 –
_I使用Pure Virtual作爲下面的內容。 **複製粘貼**問題本身的所有相關代碼。 –
請不要鏈接文字圖片,只需將相關信息複製並粘貼到您的問題中即可。 – Rook