栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

学了C再看C++(1)函数

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

学了C再看C++(1)函数




#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

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/935867.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号