数组维中的C ++模板参数 [英] C++ template parameter in array dimension

查看:90
本文介绍了数组维中的C ++模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码使用模板和数组维度作为模板非类型参数

I have have the following code using templates and array dimension as template non-type parameter

template<int n> double f(double c[n]);
...
double c[5];
f<5>(c);  // compiles
f(c);  // does not compile

不应该编译器能够实例化没有显式模板参数的第二个f ?我使用g ++ 4.1

should not the compiler to be able to instantiate the second f without explicit template parameter? I am using g++4.1

推荐答案

使用引用时可以使用:

template<size_t n> double f(double (&c)[n]);

这篇关于数组维中的C ++模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆