• 数组型参数和数组的区别


    // templatetest.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include <iostream>
    #include <typeinfo>
    template <class Type, int size>

    Type min( const Type (&r_array)[size] )
    {
        /* 找到数组中元素最小值的参数化函数 */
        Type min_val = r_array[0];

        for ( int i = 1; i < size; ++i )
            if ( r_array[i] < min_val )
                min_val = r_array[i];

        return min_val;
    }

    template <class Type, int size>
    Type min( Type (&r_array)[size] ) { /* ... */ return size; }

    void f( double pval[9] ) {
        // 错误: Type (&)[] != int*
        std::cout<<typeid(pval).name()<<std::endl;// output double *
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
        double da[8] = { 10.3, 7.2, 14.0, 3.8, 25.7, 6.4, 5.5, 16.8 };
        int i1 = min( da );
        f(da);
        std::cout<<*da<<std::endl;
        std::cout<<typeid(da).name()<<std::endl;//output double [8]
        getchar();
        return 0;
    }
  • 相关阅读:
    CSS3 not
    rxjs1
    Angular 2 组件之间如何通信?
    开发去。。
    补零补零
    MySQL数据库从复制及企业配置实践
    互联网中接口安全解决方案
    redis服务打不开--解决办法
    搭建Git服务器
    git将当前分支上修改的东西转移到新建分支
  • 原文地址:https://www.cnblogs.com/bayonetxxx/p/1803414.html
Copyright © 2020-2023  润新知