面向过程与面向对象

xiaoxiao2021-02-28  35

#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; }
转载请注明原文地址: https://www.6miu.com/read-2300159.html

最新回复(0)