java的虚方法_简单的虚拟继承和纯虚方法程序

更正:

我编辑了两行:

1)“ class 圈:公共形状”到“ class 圈子:公共虚拟形状”

2)“ class 广场:公共形状”到“ class 广场:公共虚拟形状”

是的,我试图为 shapes 类只有一个 Shape 类的实例,而在 Circle class和 Square 类中定义方法 draw 则不同

我试图做一个简单的继承程序,但它给了我以下错误:

*错误C2250:'shapes':'void shape::draw(void)'的模糊继承

IntelliSense:虚拟函数"shape::draw"的覆盖是不明确的

此代码类似于钻石问题的解决方案 . 我不明白为什么我看到这个错误 .

这是代码:

#include

using namespace std;

class shape

{

public:

shape()

{

cout << "shape created" << endl;

}

virtual void draw()=0;

};

class circle : public virtual shape

{

public:

circle()

{

cout << "circle created" << endl;

}

virtual void draw()

{

cout << "this is a circle" << endl;

}

};

class square : public virtual shape

{

public:

square()

{

cout << "square created" << endl;

}

virtual void draw()

{

cout << "this is a square" << endl;

}

};

class shapes : public circle, public square

{

public:

shapes()

{

cout << "shapes created" << endl;

}

};

void main()

{

shapes e;

cout << "-------------" << endl;

system("pause");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值