相关疑难解决方法(0)

什么是阵列衰减?

什么是阵列的衰变?与数组指针有关系吗?

c c++ arrays pointers

358
推荐指数
8
解决办法
5万
查看次数

为什么我不能将数组传递给函数模板?

我有这个来自 C++ 第五版的例子:

template <typename T> T fobj(T, T); // arguments are copied
template <typename T> T fref(const T&, const T&); // references
string s1("a value");
const string s2("another value");
fobj(s1, s2); // calls fobj(string, string); const is ignored
fref(s1, s2); // calls fref(const string&, const string&)
              // uses premissible conversion to const on s1
int a[10], b[42];
fobj(a, b); // calls f(int*, int*)
fref(a, b); // error: array types don't match
Run Code Online (Sandbox Code Playgroud)

“在接下来的一对调用中,我们传递数组参数,其中数组的大小不同,因此具有不同的类型。在调用中fobj,数组类型不同的事实并不重要。两个数组都被转换为指针。模板参数类型中fobjint*。所述的呼叫fref …

c++ arrays pointers template-argument-deduction

2
推荐指数
1
解决办法
89
查看次数

标签 统计

arrays ×2

c++ ×2

pointers ×2

c ×1

template-argument-deduction ×1