C++ 类 & 对象

C++ 类 & 对象
C++ 在 C 语言的基础上增加了面向对象编程,C++ 支持面向对象程序设计。类是 C++ 的核心特性,通常被称为用户定义的类型。

类用于指定对象的形式,它包含了数据表示法和用于处理数据的方法。类中的数据和方法称为类的成员。函数在一个类中被称为类的成员。

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int age(int);
 6 int main(int argc, char** argv) {
 7     cout <<age(5)<<endl;
 8     return 0;
 9 }
10 
11 int age(int n)
12 {
13     int c;
14     if(n==1)c=10;
15     else c=age(n-1)+2;
16     return c;
17 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9401175.html