struct G{
G&operator()(const int**a)
{
v<<a;
std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout, " "));
return *this;
}
friend std::vector<int>&operator<<(std::vector<int>&v,const int** n);
std::vector<int>v;
};
std::vector<int>&operator<<(std::vector<int>&v,const int** n)
{
v.insert(v.begin(),*n,*n+sizeof(*n)/sizeof(*n[0]));
return v;
}
/// use it
G g;
int v[8]={1,2,3,4,5,6,5,4};
g(&v);
我有两个问题,我想在克为g({1,2,3,4传递 1.错误cannot convert parameter 1 from 'int (*)[8]' to 'const int **'
2.上述代码返回的数组, 5,6,5,4})而不是g(&v)。但我不知道该怎么做,总是想知道g是否会接受它。
谢谢。传递参数作为整数
尝试使用以下内容:'template myFunction(int&myArray [N])'这种方式可以防止它在函数调用中指向int的指针衰减。 :) –