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);
I have two questions,
1. The above code returns with error cannot convert parameter 1 from 'int (*)[8]' to 'const int **'
2. I would like to pass in g as g({1,2,3,4,5,6,5,4}) instead of g(&v). But I don’t know how to do that and always wonder if g will accept it.
Thank you.
&vis giving you the address of the array, when you want the address of a pointer. Try doingconst int* x = vtheng(&x).In C++0x, you can do this: