| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 683 人关注过本帖
标题:C++ 运行错误 问题
只看楼主 加入收藏
milantgh
Rank: 2
等 级:论坛游民
帖 子:13
专家分:10
注 册:2013-1-20
收藏
 问题点数:0 回复次数:7 
C++ 运行错误 问题
#include <iostream.h>

class Base1
{
    int b1;

public:
   
    Base1 (int i)
    {
        b1 = i;

        cout << "Constructor Base1." << endl;
    }

    ~Base1 ()
    {
        cout << "Destructor Base1." << endl;
    }

    void Print ()
    {
        cout << b1 << '\t';
    }
};

class Base2
{
    int b2;

public:
   
    Base2 (int i)
    {
        b2 = i;

        cout << "Constructor Base2." << endl;
    }

    ~Base2 ()
    {
        cout << "Destructor Base2." << endl;
    }

    void Print ()
    {
        cout << b2 << '\t';
    }
};

class Base3 :public Base2
{
    int b3;

public:
   
    Base3 (int i, int j) : Base2 (i)
    {
        b3 = j;

        cout << "Constructor Base3." << endl;
    }

    ~Base3 ()
    {
        cout << "Destructor Base3." << endl;
    }

    void Print ()
    {
        Base2:: Print ();

        cout << b3 << '\t';
    }

    class Base4
    {
        int b4;

    public:
        
        Base4 ()
        {
            b4 = 0;

            cout << "Constructor Base4." << endl;
        }

        ~Base4 ()
        {
            cout << "Destructor Base4." << endl;
        }

        void Print ()
        {
            cout << b4 << '\t';
        }
    };
};

class Member
{
    int m;

public:
   
    Member (int i)
    {
        m = i;

        cout << "Constructor Member." << endl;
    }

    ~Member ()
    {
        cout << "Destructor Member." << endl;
    }

    int GetM ()
    {
        return m;
    }


};

class Derived :public Base3, public Base1, public Base4
{
    int d;

    Member mem;

public:
   
    Derived (int i, int j, int k, int l, int q);

    ~Derived ();

    void Print ();
};

Derived:: Derived (int i, int j, int k, int l, int q) : Base1 (i) , Base3 (j, k), mem (l)
{
    d = q;

    cout << "Constructor Derived." << endl;
}

Derived:: ~Derived ()
{
    cout << "Destructor Derived." << endl;
}

void Derived:: Print ()
{
    Base4:: Print ();

    Base1:: Print ();

    Base3:: Print ();

    cout << mem.GetM () << '\t';

    cout << d << endl;
}

void main (void)
{
    Derived obj (1, 2, 3, 4, 5);

    obj.Print ();
}
搜索更多相关主题的帖子: include public 
2013-01-20 17:39
milantgh
Rank: 2
等 级:论坛游民
帖 子:13
专家分:10
注 册:2013-1-20
收藏
得分:0 
怎么解决 大神帮忙!!!
2013-01-20 17:40
liao25428301
Rank: 2
等 级:论坛游民
帖 子:13
专家分:26
注 册:2012-12-15
收藏
得分:0 
错误在哪里啊 贴出来啊
2013-01-20 18:10
milantgh
Rank: 2
等 级:论坛游民
帖 子:13
专家分:10
注 册:2013-1-20
收藏
得分:0 
回复 3楼 liao25428301
派生类综合示例.cpp
F:\C++编程\派生类综合示例.cpp(128) : error C2504: 'Base4' : base class undefined
F:\C++编程\派生类综合示例.cpp(156) : error C2352: 'Base3::Base4::Print' : illegal call of non-static member function
        F:\C++编程\派生类综合示例.cpp(94) : see declaration of 'Print'
Error executing cl.exe.

派生类综合示例.obj - 2 error(s), 0 warning(s)
2013-01-20 18:50
milantgh
Rank: 2
等 级:论坛游民
帖 子:13
专家分:10
注 册:2013-1-20
收藏
得分:0 
错误提示如上。。。
2013-01-20 18:51
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
class Base4
    {
        int b4;

    public:
        
        Base4 ()
        {
            b4 = 0;

            cout << "Constructor Base4." << endl;
        }

        ~Base4 ()
        {
            cout << "Destructor Base4." << endl;
        }

        void Print ()
        {
            cout << b4 << '\t';
        }
    };
};《--此处多了一个“};”删除即可
2013-02-24 08:23
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
class Base3 :public Base2
{
    int b3;

public:
   
    Base3 (int i, int j) : Base2 (i)
    {
        b3 = j;

        cout << "Constructor Base3." << endl;
    }

    ~Base3 ()
    {
        cout << "Destructor Base3." << endl;
    }

    void Print ()
    {
        Base2:: Print ();

        cout << b3 << '\t';
    }
《--此处少了一个“};”加上即可

2013-02-24 08:25
wzhdong1
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-11-18
收藏
得分:0 
改正好的程序如下,已调试执行过,用windiff工具一对比就知道你的错在哪里了
#include <iostream>
using namespace std;
class Base1
{
    int b1;

public:

    Base1 (int i)
    {
        b1 = i;

        cout << "Constructor Base1." << endl;
    }

    ~Base1 ()
    {
        cout << "Destructor Base1." << endl;
    }

    void Print ()
    {
        cout << b1 << '\t';
    }
};

class Base2
{
    int b2;

public:

    Base2 (int i)
    {
        b2 = i;

        cout << "Constructor Base2." << endl;
    }

    ~Base2 ()
    {
        cout << "Destructor Base2." << endl;
    }

    void Print ()
    {
        cout << b2 << '\t';
    }
};

class Base3 :public Base2
{
    int b3;

public:

    Base3 (int i, int j) : Base2 (i)
    {
        b3 = j;

        cout << "Constructor Base3." << endl;
    }

    ~Base3 ()
    {
        cout << "Destructor Base3." << endl;
    }

    void Print ()
    {
        Base2:: Print ();

        cout << b3 << '\t';
    }
};

class Base4
    {
        int b4;

    public:

        Base4 ()
        {
            b4 = 0;

            cout << "Constructor Base4." << endl;
        }

        ~Base4 ()
        {
            cout << "Destructor Base4." << endl;
        }

        void Print ()
        {
            cout << b4 << '\t';
        }
    };


class Member
{
    int m;

public:

    Member (int i)
    {
        m = i;

        cout << "Constructor Member." << endl;
    }

    ~Member ()
    {
        cout << "Destructor Member." << endl;
    }

    int GetM ()
    {
        return m;
    }


};

class Derived :public Base3, public Base1, public Base4
{
    int d;

    Member mem;

public:

    Derived (int i, int j, int k, int l, int q);

    ~Derived ();

    void Print ();
};

Derived:: Derived (int i, int j, int k, int l, int q) : Base1 (i) , Base3 (j, k), mem (l)
{
    d = q;

    cout << "Constructor Derived." << endl;
}

Derived:: ~Derived ()
{
    cout << "Destructor Derived." << endl;
}

void Derived:: Print ()
{
    Base4:: Print ();

    Base1:: Print ();

    Base3:: Print ();

    cout << mem.GetM () << '\t';

    cout << d << endl;
}

void main ()
{
    Derived obj (1, 2, 3, 4, 5);

    obj.Print ();

   
}
2013-02-27 16:52
快速回复:C++ 运行错误 问题
数据加载中...
 
   



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

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