C++ C++;模板函数在Visual Studio中不起作用

C++ C++;模板函数在Visual Studio中不起作用,c++,visual-studio,templates,C++,Visual Studio,Templates,我正在练习一个模板示例。代码如下: //template_practice.h #pragma once template<typename T, unsigned N> void print_arry(ostream &out,const T (&arry)[N]) { for (T* i = cbegin(arry); i != cend(arry); i++) { out << *i << " ";

我正在练习一个模板示例。代码如下:

//template_practice.h
#pragma once

template<typename T, unsigned N> 
void print_arry(ostream &out,const T (&arry)[N]) 
{
    for (T* i = cbegin(arry); i != cend(arry); i++) 
    {
        out << *i << " ";
    }
    out << endl;
}

//main.cpp
#include "stdafx.h"
using namespace std;

int main()
{
    int test[10] = { 1,2,3,4,5,6,7,8,9,10 };
    print_arry<int, 10> (cout, test);

    getchar();
    return 0;
}

//stdafx.h
//... (library headers)
#include "template_practice.h"
//template\u practice.h
#布拉格语一次
模板
无效打印(打印和输出、施工和安装)[N])
{
for(T*i=cbegin(arry);i!=cend(arry);i++)
{
首先,在
模板.h
中添加
#包括
(对于
std::ostream
std::endl
)和
#包括
(对于
std::cbegin
std::cend
),并在使用时添加
std:
。(顺便说一句)

其次,
cbegin(arry);
返回
const T*
,因此将
i
的类型更改为
const T*
,或者改用
auto
;例如,
for(auto i=cbegin(arry);i!=cend(arry);i++


@yughred您也不需要
print\u arry
可以根据您传入的内容类型推断模板参数。很高兴知道。谢谢。