2016/10/3

来源:互联网 发布:比特大陆 知乎 编辑:程序博客网 时间:2024/06/03 18:45
*/1631-5 黄加勉 <2016.10.3>
 连续第2天总结*/
 
namesapce A(今日任务)
{
1.const及其用法(100%);
2.函数重载(100%);
3.温习一下指针和引用(80%);
}


namespace B(具体内容)
{
之前一直以为const是一个变量类型,现在才发现应该是修饰一个变量的,使它变成常量;
函数重载是个好东西;
比起用命名空间,重载感觉更高效(目前来说是),起码不用再打一堆namespace XXX和::了;
而且有函数重载的功能感觉可读性更强了,一个print想打啥都行;
}






//附上代码:


#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;


typedef struct
{
char x;
char y;
}coord;




void print(int a);
void print(coord b);
void print(double x);
void print(int arr[]);
void print(unsigned int k, char l);




int  main(void)
{
system("color F0");
const double pi = 3.14159265358979;
int arr[5] = { 1,2,3,4,5 };
int r = 1;
int *p = &r;
int *&q = p;
int **m = &q;
int **&n = m;
int ***a = &n;
int ***&b = a;
int ***&o = b;
***o = 486;
coord A;
A.x = 'B';
A.y = 'C';
print(A);
print(10);
print(arr);
print(pi);
print(r, 'w');
system("pause");
}


void print(int a)
{
cout << a << endl;
}


void print(coord b)
{
cout << b.x <<","<<b.y<< endl;
}


void print(double x)
{
cout << setprecision(15) << x << endl;
}


void print(int arr[])
{
for (int i = 0; i < 5; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}


void print(unsigned int k, char l)
{
cout << k * 10 << endl;
}








/*还有:vc6.0以后用“include<iostream>;using namespace std;”!!!!!!!!!!!!!!!
#include<iostream.h>不能通过!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
血的教训!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/


*/还有:cout默认输出double精度是六位
加<< setprecision(n)(n为精度) 就可以控制输出精度了
另外还要加#include <iomanip>,也是在std里面的,没有.h的后缀*/






namespace C
{
1.内存管理;
2.类和对象了解一下;
}






1 0
原创粉丝点击