瑞星卡卡安全论坛技术交流区系统软件 各位高手请看一下下面的c++程序看看错在哪?

1   1  /  1  页   跳转

各位高手请看一下下面的c++程序看看错在哪?

各位高手请看一下下面的c++程序看看错在哪?

课本的例题.就是编译不出来,很郁闷
//多重继承,从多个基类派生出来的类,多文件形式
#ifndef BASE1_H
#define BASE1_H
class Base1{
    int value;
public:
    Base1(int x){value=x;}
    int getData() const {return value;}
};
#endif

#ifndef BASE2_H
#define BASE2_H
class Base2{
    char letter;
public:
    Base2(char c) {letter=c;}
    char getData() const {return letter;}
};
#endif

#ifndef DERIVED_H
#define DERIVED_H
#include "base1.h"
#include "base2.h"
class Derived : public Base1,public Base2
{
    double real;
public:
    Derived(int,char,double);
    double getReal() const;
    void Output();
};
#endif

//derived.cpp document
#include<iostream>
#include "derived.h"
using namespace std;
Derived::Derived(int i,char c,double f):Base1(i),Base2(c),real(f){ }
double Derived::getReal() const {return real;}
void Derived::Output()
{
    cout<<"Integer:"<<Base1::gerData()<<Base2::getData()
        <<"\nCharacter:"<<Base2::getData()
        <<"\nReal unmber:"<<real<<endl;
}
//Example 10_7.cpp document reborn class
#include<iostream>
#include"base1.h"
#include"base2.h"
#include"derived.h"
using namespace std
int main()
{
    Base1 b1(10),*base1Ptr=0;
    Base2 b2('z'), *base2ptr=0;
    Derived(7,'A',3.5);
    cout<<" Object b1 contains integer"<<b1.getData()
        <<"\nobject b2 contains character"<<b2.getData()
        <<"\nObject d contains:\n";
    d.Output;

    cout<<"Data members of Derived can be"<<"accessd individually:"
        <<"\nInter:"<<d.Base1::getData()<<"\ncharacter:"<<d.Base2::getData()
        >>"\nreal numbers:"<<d.getReal()<<endl;
    cout<<"Derived can be treated as an"<<"abject of either base class:\n;

        base1Ptr=&d;
    cout<<"base1Ptr->getData()"<<base1Ptr->getData()<<'\n';
    base2Ptr=&d;
    cout<<"base2Ptr->getData()"<<base2Ptr->getData()<<endl;
    return 0;
}
最后编辑2006-02-13 12:44:35
分享到:
gototop
 

不太懂,应该有编译错误的提示吧
gototop
 

有提示,但看不懂呀
gototop
 

没学过,所以我觉得是——天书
gototop
 

你那几个文件都齐了吗?
编译器说什么?
gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT