-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