资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

一段overriding的代码编译不通过,不知为什么?

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

代码如下  
  #include   <stdio.h>  
  class   Tree  
  {  
  public:  
  virtual   Tree&   Subtree()    
  {  
  printf("%s\n",   "Tree");  
  return   *this;  
  }  
  };  
  class   GeneralTree   :   public   Tree  
  {  
  public:  
  GeneralTree&   Subtree()  
  {  
  printf("%s\n",   "GeneralTree");  
  return   *this;  
  }  
  };  
  int   main()  
  {  
  return   0;  
  }  
   
 

网友回答:

发表者:ywhimis

DEV-C++,C_Free   BCB都可以编译通过

发表者:TomMfc

返回值不同是不能用overridde

发表者:TomMfc

#include   <stdio.h>  
  class   Tree  
  {  
  public:  
  virtual   Tree*   Subtree()    
  {  
  printf("%s\n",   "Tree");  
  return   this;  
  }  
  };  
  class   GeneralTree   :   public   Tree  
  {  
  public:  
  tree*   Subtree()  
  {  
  printf("%s\n",   "GeneralTree");  
  return   this;  
  }  
  };  
 

发表者:newegg2002

返回值类型不同应该不算函数标识不同吧...  
  在继承派生关系中.若基类中某函数被声明为virtual,  
  而在派生类中有着相同的函数标识的函数..则将重写基类的虚函数.  
  我觉得楼主代码中的重写是成功的...

发表者:bailingke

考虑到类型的隐式转换,返回值不能作为override的。


 

 
热门推荐笔记本: 戴尔笔记本
相关文章:
笔记本相关:
IT技术文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved