| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 622 人关注过本帖
标题:编译时奇怪的问题 貌似二义性了 但是在哪儿? 求解
取消只看楼主 加入收藏
at445
Rank: 1
等 级:新手上路
帖 子:19
专家分:4
注 册:2011-6-14
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:0 
编译时奇怪的问题 貌似二义性了 但是在哪儿? 求解
#include <cstdlib>
#include <iostream>
using namespace std;
class Base
{
     private:
         int number;
         char name[10];
     public:
         Base(int a,char *n)
         {
                  number = a;
                  strcpy(name,n);
         }
         void show()
         {
              cout<<number<<'\t'<<name;     
         }                     
};

class Book:public Base
{
      private:
          char author[10];
      public:
          Book(int no,char *book, char *aut):Base(no,book)
          {
               strcpy(author,aut);
          }
          void show()
          {
               Base::show();
               cout<<'\t'<<author<<endl;
          }
};

class Reader:public Base
{
      private:
          int amount;
          Book books[10];
      public:
          Reader(int no,char *reader):Base(no,reader)
          {
               amount=0;           
          }
          void show(void)
          {
               cout<<"reader ";
               Base::show();   
               cout<<endl;
               cout<<"    borrow:"<<endl;
               for(int i=0; i<amount; i++)
               {
                    cout<<"         "<<i+1<<":";
                    books[i].show();
               }
          }
          void borrow(Book &b)
          {
               books[amount++]=b;
          }
};               
int main(int argc, char *argv[])
{
    Book book[]={Book(1,"hello","chen"),
              Book(2,"hi","chen"),
              Book(3,"fine","chen"),
              Book(4,"bye","chen")};
    Reader reader[]={  Reader(1,"zhang"),
                       Reader(2,"wang")};
    reader[0].borrow(book[1]);
    reader[1].borrow(book[4]);
    reader[0].show();
    reader[1].show();
    system("PAUSE");
    return EXIT_SUCCESS;
}
搜索更多相关主题的帖子: class void private include public 
2012-01-09 20:39
快速回复:编译时奇怪的问题 貌似二义性了 但是在哪儿? 求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026661 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved