首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

vc++2005中怎么实现递归函数

2013-08-06 
vc++2005中如何实现递归函数以下是一个在树形控件中查找某项的递归函数,在vc6中正常,但在vc2005中出错:er

vc++2005中如何实现递归函数
以下是一个在树形控件中查找某项的递归函数,在vc6中正常,但在vc2005中出错:"error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject",这表明,在vc2005以上的版本中好象无法实现递归函数了,那么该怎么解决呢?

finditem(CTreeCtrl tree,HTREEITEM item,CString strtext)    
{
   HTREEITEM  hfind;   
   if(item== NULL)//空树,直接返回NULL    
      return  NULL;   
   while(item!=NULL)//遍历查找    
   {   
      if(tree.GetItemText(item) == strtext)//当前节点即所需查找节点   
         return item;   
      if(tree.ItemHasChildren(item))//查找当前节点的子节点   
      {   
         item=tree.GetChildItem(item);  
         hfind=finditem(tree,item,strtext);//递归调用,在vc2005中引起错误
         if(hfind)   
         {
            return  hfind;
         }   
         else   //子节点中未发现所需节点,继续查找兄弟节点 
         item = tree.GetNextSiblingItem(tree.GetParentItem(item));   
      }   
      else
  {   //若无子节点,继续查找兄弟节点 
         item =tree.GetNextSiblingItem(item);   
      }   
   }   
   return item;
}
[解决办法]
这不是说不能实现递归,英文意思是:不能访问类CObject的私有变量
[解决办法]
VS2005递归生成树
------解决方案--------------------


Compiler Error C2248
Members of a derived class cannot access private members of a base class. You cannot access private or protected members of class instances.

http://blog.csdn.net/vincent_lon/archive/2008/09/19/2950218.aspx

热点排行