#include
#include
#define DAY2
using namespace std;
void day2();
#ifdef DAY2
void day2()
{
string s1 = "内联函数:n会将函数调用直接替换为代码,增加空间,节省时间。n使用时声明或定义前加关键字inlinen跟宏类似,个人感觉不如宏。n";
string s2 = "n引用:n相当于const指针,跳转函数时不需要解引用,n一个变量的地址不会改变,除非让它消失,所以引用无法改变,跟随变量。nint &a; int const *b;a相当于*bn相比*b,a的好处是少写了个*其它都和int const * 一样。(&a)++是无效的n";
string s3 = "n默认参数:n不传参时候用默认参数。n声明定义只有一个能带默认参数n";
string s4 = "n重载:同一个函数名不同功能的意思n重载函数名、作用域、相同。参数的类型个数应该不同n";
string s5 = "n模板:对于一个函数,即使传入不同类型的参数也能实现相似功能n声明如下:n templatenvoid swap(T a,T b){}//class T(C98)n";
std::cout << (s1 + s2 + s3 + s4 + s5)<
T* max5(T *a ,int n)
{
T* p = new(T);
T temp;
for (; n >0; n--)
{
if (a[n] > a[n - 1])temp = a[n];
else temp = a[n - 1];
}
*p = temp;
return p;
}
//重载魔板,称为具体实现
template<>
char* max5(char* a, int n)
{
int location=0;
int n1=0, n2=0;
for (int i=0; i n2)
{
n2 = n1; location = i;
}
n1 = 0;
}
else
{
n1++;
}
}
cout << location-n2 << endl;
//n = 1;
return (a + location-n2);
}
//测试
void max_test()
{
char c[60] = "like best all laplace newbi hello world";
cout << "重载测试" << endl;
int a[5] = { 10,90,60,80,70 };
double b[5] = { 3.14,1.41,1.73,1.14514,1.7 };
cout << *(max5(a, 5))<> wt;
file << "users:" << wt << endl;
file.close();
}
while (ifile.good())
{
ifile >> s;
cout << endl << "flie:" << endl;
cout << s << endl;
i += s.length();
cout << "file length:" << i << endl;
}
ifile.close();
#endif
#ifdef DAY2
day2();
string s = "upper";
day2_struper(s);
max_test();
#endif
}