| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 608 人关注过本帖
标题:急求 多继承派生程序错误!急!急
只看楼主 加入收藏
zhonglai123
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-7-23
收藏
 问题点数:0 回复次数:3 
急求 多继承派生程序错误!急!急
哪位大虾看一下我的这个程序
是关于派生类的多继承的 这个程序要是不要带参数可以运行通过
但是加上参数后就显示下面的错误 仔细查了没有错误啊为什呢
这个程序是我从教材上的抄下来的
#include<iostream.h>
Class base1
{
 Public:
    base1(int i)
    {
      cout<<"constrcting base1"<<endl;
          x1=i;
        }
    void print()
    {cout<<"x1= "<<x1<<endl;
    }
 protected:
    int x1;
};
class base2
{
public:    
    base2(int j)
    {cout <<"constructing base2"<<endl;
     x2=j;
    }
    void print()
    {cout<<"x2="<<x2<<endl;
    }
    proteced:
    int x2;
};
class base3
{
public:
    base3()
    {cout<<"constructing class base3"<<endl;
    }
    void print()
    {cout<<"constructing class base3 no values"<<endl;
    }
};
class M : public base1,public base2, public base3
    {
     public:
         M(int a,int b,int c,int d):base1(a),A(c),base2(b),B(d){}
     void print()
     { base1::print();
       base2::print();
       base3::print();
     }
    };
void main()
{ M obj(1,2,3,4);
 obj.print();
}

显示的错误是:
error c2629: unexpected 'class M ('
error c2334: unexpected token(s) proceding ':';skipping apparent function body
error c2660: M::M :function does not take 4 paraments

[[it] 本帖最后由 zhonglai123 于 2008-8-13 17:32 编辑 [/it]]
搜索更多相关主题的帖子: 程序错误 教材 参数 int 
2008-08-13 17:30
zhonglai123
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-7-23
收藏
得分:0 
回复 1# zhonglai123 的帖子
请大侠们给我个回复吧
急死我了
2008-08-13 17:31
zerocn
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-4-11
收藏
得分:0 
不知道你是再这里打的还是怎么样,很多错误

以下的编译通过,错误的地方请对应查找
#include <iostream>
#include <stdlib.h>
using namespace std;

class base1//class 的大小写
{
public://还是大小写
    base1(int i)
    {
      cout<<"constrcting base1"<<endl;
          x1=i;
        }
    void print()
    {cout<<"x1= "<<x1<<endl;
    }
protected:
    int x1;
};

class base2
{
public:   
    base2(int j)
    {cout <<"constructing base2"<<endl;
     x2=j;
    }
    void print()
    {cout<<"x2="<<x2<<endl;
    }
    protected://打错!!protected:
    int x2;
};

class base3
{
public:
    base3()
    {cout<<"constructing class base3"<<endl;
    }
    void print()
    {cout<<"constructing class base3 no values"<<endl;
    }
};

class M : public base1,public base2, public base3
{
     public:
     M(int a,int b,int c,int d):base1(a),base2(b){}//没有A、B成员!
     void print()
     { base1::print();
       base2::print();
       base3::print();
     }
};
int main()
{ M obj(1,2,3,4);
  obj.print();
  system("pause");
  return 0;
}

[[it] 本帖最后由 zerocn 于 2008-8-13 18:22 编辑 [/it]]
2008-08-13 18:21
elegant87
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2008-1-15
收藏
得分:0 
#include<iostream>

using namespace std;

class base1
{
public:
    base1(int i)
    {
          cout<<"constrcting base1"<<endl;
          x1=i;
    }
    void print()
    {
         cout<<"x1= "<<x1<<endl;
    }
protected:
    int x1;
};
class base2
{
public:   
    base2(int j)
    {
         cout <<"constructing base2"<<endl;
         x2=j;
    }
    void print()
    {
         cout<<"x2="<<x2<<endl;
    }
protected:
    int x2;
};

class base3
{
public:
    base3()
    {
         cout<<"constructing class base3"<<endl;
    }
    void print()
    {
         cout<<"constructing class base3 no values"<<endl;
    }
};
class M : public base1,public base2, public base3
{
public:
     M(int a,int b,int c,int d):base1(a),base2(b),A(c),B(d){}
     void print()
     {
           base1::print();
           base2::print();
           base3::print();
     }
protected:
     int A;
     int B;
};

int main()
{
     M obj(1,2,3,4);
     obj.print();
     system("pause");
     return 0;
}
2008-08-13 21:24
快速回复:急求 多继承派生程序错误!急!急
数据加载中...
 
   



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

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