您的位置:首页 > 编程语言 > C语言/C++

面向过程与面向对象

2018-03-12 15:28 211 查看
#include<iostream>
using namespace std;

class Dog
{
public:
char name[64];

void eat(char *food)
{
cout << name << "吃" << food <<endl;
}

};

//面向过程
void eat(class Dog &dog,char *food)
//class Dog &dog = dog ; char *food = "翔";
{
cout << dog.name << "吃" << food << endl;
}

int main()
{
//面向过程
Dog dog;
strcpy(dog.name,"狗");
eat(dog,"翔");

cout << "------------" << endl;
//面向对象
dog.eat("翔");

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  面向对象 c++