PDA

View Full Version : مثالی ساده از وراثت چندگانه



Salar Ashgi
جمعه 11 مرداد 1387, 08:57 صبح
کد در کامپایلر Borland C++ Version 5.02 :


#include <iostream>
#include <conio>
class Vasile_Naghliye{
protected:
int tedad_dande;
public:
int silandr;
};
//------------------
class motorciklet{
public:
int speed_max;
};
//------------------
class Otomobile:public Vasile_Naghliye,public motorciklet{
public:
Otomobile(int=4);
void dande(int=6);
void print();
private:
int tedad_charkh;
};
Otomobile::Otomobile(int k){
tedad_charkh=k;
}
void Otomobile::dande(int d){
tedad_dande=d;}
void Otomobile::print(){
cout<<silandr<<" "<<tedad_charkh<<" "<<tedad_dande<<" "<<speed_max<<"\n";
}
//------------------
int main(){
Otomobile o(4);
o.silandr=8;
o.speed_max=280;
o.dande(7);
o.print();
getch();
}