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

类中的复制构造函数的参数(也就是那个类的一个对像)不能访问这个类的公有函数吗?

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


热门软件下载:


   

 
  #include   <iostream>  
  using   namespace   std;  
   
  template   <class   T>  
  class   list;  
   
  template   <class   T>  
  class   listdate{  
          friend   class   list<T>;  
        public:    
          T   date;                                       //节点里面数据    
          listdate<T>*   us;                       //指向下一个节点指针    
  };  
   
  template   <class   T>  
  class   list{  
          public:  
          listdate<T>*   first;           //链表头指针    
          listdate<T>*   lost;           //末尾指针    
           
                  list(){   first   =   lost   =   0;}  
                  ~list(){  
                          listdate<T>*   dec   =   first;  
                          while(first)  
                          {  
                                  dec   =   first->us;  
                                  delete   first;  
                                  first   =   dec;  
                            }  
                             
                    }  
                  list&   sernt(T   x)       //链表后面   插入数据    
                  {  
                          listdate<T>*   c   =   new   listdate<T>;  
                          c->date   =   x;  
                          c->us   =   0;  
                          if(!first)  
                          {  
                                  lost   =   first   =   c;  
                          }  
                          else                  
                            {  
                            lost->us   =   c;  
                            lost   =   c;  
                            }          
                          return   *this;  
                  }  
                  friend   ostream&   operator<<(ostream&   out,const   list<T>&   x)  
                  {  
                          listdate<T>*   a   =   x.first;  
                          while(a)  
                          {  
                                  out   <<   a->date   <<   endl;  
                                  a   =   a->us;  
                          }  
                          return   out;  
                  }        
                  int   number()     //计算表的元素数目    
                  {  
                          int   a   =   0;  
                          listdate<T>*   c   =   first;  
                          while(c)  
                          {  
                                  a++;  
                                  c   =   c->us;  
                          }    
                          return   a;  
                  }                              
                  list(const   list<T>&   a)//不知道这里那有问题!  
                  {  
                          listdate<T>*   box   =   new   listdate<T>;  
                          listdate<T>*   c   =   a.first;  
                          first   =   lost   =   box;  
                          int   i   =   0;  
                          while(c)  
                          {  
                                    i++;  
                                    lost->date   =   c->date;  
                                  if   (i   ==   (a.number()   -   1))//类中的复制构造函数的参数不能调用类中的公有方法吗?   这里不能用number()   ,通不过呀!  
                                      {    
                                        lost->us   =   0;  
                                        break;  
                                      }          
                                    box   =   new   listdate<T>;  
                                  lost->us   =   box;                      
                                  lost   =   box;  
                                  c   =   c->us;                            
                            }                                          
                           
                  }    
                  list<T>&   operator=(list<T>   a)//不知道这里那有问题!  
   
                  {  
                          if(this   ==   &a)  
                          return   *this;  
                        listdate<T>*   box   =   new   listdate<T>;  
                          listdate<T>*   c   =   a.first;  
                          first   =   lost   =   box;  
                          int   i   =   0;  
                          while(c)  
                          {  
                                    i++;  
                                    lost->date   =   c->date;  
                                  if   (i   ==   (a.number()   -   1))  
                                      {    
                                        lost->us   =   0;  
                                        break;  
                                      }          
                                    box   =   new   listdate<T>;  
                                  lost->us   =   box;                      
                                  lost   =   box;  
                                  c   =   c->us;                                                                  
                          }                
                          return   *this;  
                  }                
                                 
          };  
   
  template   <class   T>  
  list<T>   toC(list<T>&   A,list<T>&   B);    
  int   main()  
  {  
          list<int>   a,b;  
          a.sernt(10);  
          a.sernt(20);  
          a.sernt(30);  
          b.sernt(10);  
          b.sernt(10);  
          list<int>   c   ;  
          c   =   toC(a,b);  
          list<int>   d   =   c;  
          cout   <<   c.number()   <<   endl;  
          cout   <<   c   <<   endl;  
          cout   <<   d   <<   endl;  
          system("pause");  
          return   0;  
  }                
  template   <class   T>  
  list<T>   toC(list<T>&   A,list<T>&   B)   //两个表合并成一个表并返回    
    {  
            list<T>   c;  
            c.first   =   A.first;  
            A.lost->us   =   B.first;  
            c.lost   =   B.lost;  
            return   c;  
                     
    }                            
    高手指点

网友回答:

发表者:playmud

发表者:flyelf

gx

发表者:zhangfjj

^_^   捡分啰!

发表者:airwudi

hehe

发表者:ftkghost

gx


 

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