鱼C论坛

 找回密码
 立即注册
查看: 4089|回复: 8

求眼力好的大神,帮我看看这2程序有神马不同..一段能编译,一段不能..神马情况啊

[复制链接]
发表于 2013-5-28 12:13:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;

  4. class vehicle
  5. {
  6. public:
  7. // vehicle(){};
  8. virtual void run()
  9. {
  10. cout<<"vehicle run"<<endl;
  11. }
  12. virtual void stop()
  13. {
  14. cout<<"vehicle stop"<<endl;

  15. }
  16. };

  17. class bicyle : virtual public vehicle//
  18. {
  19. public:
  20. void run()
  21. {
  22. cout<<"bicyle run"<<endl;
  23. }
  24. void stop()
  25. {
  26. cout<<"bicyle stop"<<endl;
  27. }
  28. };

  29. class motorcar:virtual public vehicle//
  30. {
  31. public:
  32. void run()
  33. {
  34. cout<<"motorcar run"<<endl;
  35. }
  36. void stop()
  37. {
  38. cout<<"motorcar stop"<<endl;
  39. }

  40. };

  41. class motorcycle:public bicyle,motorcar
  42. {
  43. public:
  44. void run()
  45. {
  46. cout<<"motorcycle run"<<endl;
  47. }
  48. void stop()
  49. {
  50. cout<<"motorcycle stop"<<endl;
  51. }
  52. };

  53. void show(vehicle *p)
  54. {
  55. p->run();
  56. p->stop();
  57. }





  58. int main()
  59. {
  60. vehicle *p,a;
  61. bicyle b;
  62. motorcar c;
  63. motorcycle d;
  64. p=&a;
  65. show(p);
  66. p=&b;
  67. show(p);
  68. p=&c;
  69. show(p);
  70. p=&d;
  71. show(p);

  72. return 0;

  73. }
复制代码

上面那段是可以编译的,下面这段却不能,为什么啊。。老师帮我改了,却没有告诉错的位置

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class vehicle
  5. {
  6. public:
  7. // vehicle(){};
  8. virtual void run()
  9. {
  10.   cout<<"vehicle run"<<endl;
  11. }
  12. virtual void stop()
  13. {
  14.   cout<<"vehicle stop"<<endl;
  15. }
  16. };
  17. class bicyle : public vehicle
  18. {
  19. public:
  20. void run()
  21. {
  22.   cout<<"bicyle run"<<endl;
  23. }
  24. void stop()
  25. {
  26.   cout<<"bicyle stop"<<endl;
  27. }
  28. };
  29. class motorcar:public vehicle
  30. {
  31. public:
  32. void run()
  33. {
  34.   cout<<"motorcar run"<<endl;
  35. }
  36. void stop()
  37. {
  38.   cout<<"motorcar stop"<<endl;
  39. }
  40. };
  41. class motorcycle:public bicyle,motorcar
  42. {
  43. public:
  44. void run()
  45. {
  46.   cout<<"motorcycle run"<<endl;
  47. }
  48. void stop()
  49. {
  50.   cout<<"motorcycle stop"<<endl;
  51. }
  52. };
  53. void show(vehicle *p)
  54. {
  55. p->run();
  56. p->stop();
  57. }


  58. int main()
  59. {
  60. vehicle *p,a;
  61. bicyle b;
  62. motorcar c;
  63. motorcycle d;
  64. p=&a;
  65. show(p);
  66. p=&b;
  67. show(p);
  68. p=&c;
  69. show(p);
  70. p=&d;
  71. show(p);
  72. return 0;
  73. }
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-5-28 12:15:28 | 显示全部楼层
强烈支持楼主ing……
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 12:15:35 | 显示全部楼层
求各种大神啊........  求亮爷!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 12:16:48 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 12:20:56 | 显示全部楼层
这里能@的吗 --求亮爷  @小亮1201
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-5-28 12:37:58 | 显示全部楼层
virtual public
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 16:38:52 | 显示全部楼层

什么意思,第几行错误啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 22:44:00 | 显示全部楼层
求不沉贴啊...求帮助,不要路人啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-29 11:46:05 | 显示全部楼层
发觉在这里问问题好像已经没有用了,都没有人来回答的...一开始我以为这里寻求帮助比较快,后来发现去百度还是比较好...大家都只是看不帮助的..发那么多回复还不是想把这帖子顶上去让人看到,,不知道的人还以为我在灌水,刷YB呢。.以后不求助这里了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-27 16:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表