- 对继承关系的描述转化为c++代码
-class sublclass: public superClass{…}-class pig : public Animal{…}
- 工具 -- 这里介绍一款 编译器 code:Blocks svn bulid 各种集合
#include <iostream>#include <string>
class Animal //this is a super{public:
std::string mouth;
void eat ();// error: candidate is: void Animal::eat()void sleep();
void drool();
};class pig:public Animal{public :
void climb();
};class turtle:public Animal{public:
void swim();
};void Animal::eat()
{std::cout<<"我在吃饭"<<std::endl;
}void Animal::sleep()
{std::cout<<"我在睡觉,别打扰我"<<std::endl;
}void Animal::drool()
{std::cout<<"我为什么在流口水,我要吃猪尾巴"<<std::endl;
}void pig::climb()
{std::cout<<"你是母猪,你才上树呢"<<std::endl;
}void turtle::swim()
{std::cout<<"我是乌龟,我会游泳"<<std::endl;
}int main(int argc, char *argv[]){pig Pig;turtle Turtle;Pig.eat();Turtle.eat();Pig.climb();Turtle.swim();return 0;
}
结果: