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



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

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