// 通过这个小程序复习了一下 命名空间 、 const 、函数重载 、类的定义、类的两种实例化方式;
// 初步理解了C++ 特性的前提,把函数和类武装到牙齿,从 C面向过程 转变成 一门面向对象的语言;
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 5;
namespace AA
{
int x = 20;
int y = 30;
}
class Aassd
{
public:
int x;
void outx(){
cout << x << endl;
}
};
class Bassd
{
public:
int x;
int y;
int arr[5];
void outx(){
cout << x << endl;
}
void outy(){
cout << y << endl;
}
void outarr(){
for( int i=0; i<MAXN; i++ ){
cout << arr[i] << endl;
}
}
};
int gax( float a,int b );
int gax( int a,int b,int c);
int gax( int a,int c );
int gax( float a,float b,double c,double d);
int main()
{
Aassd coor;
coor.x = 10 ;
coor.outx();
Bassd *coortwo = new Bassd();
if( coortwo == NULL ){
return 0;
}
coortwo->x = AA::x;
coortwo->y = AA::y;
coortwo->outx();
coortwo->outy();
for( int i=0; i<MAXN; i++ )
{
coortwo->arr[i] = i;
}
coortwo->outarr();
delete coortwo;
coortwo = NULL;
gax(AA::x,AA::y);
printf("\n");
gax((float)AA::x,AA::y);
printf("\n");
float mid = AA::x*1.23;
gax(mid,AA::x,AA::y,AA::y);
return 0;
}
int gax( float a,int b )
{
cout << "1 //" << a << " " << b << endl;
}
int gax( int a,int b,int c){
cout << "2 //" << a << " " << b << " " << c << endl;
}
int gax( int a,int c ){
cout << "3 //" << a << " " << c << endl;
}
int gax( float a,float b,double c,double d){
cout << "4 //" << a << " " << b <<" " << c << " " << d << endl;
}
第一章复习
最新推荐文章于 2022-03-08 17:14:48 发布