I give the following example to illustrate my question:
template<typename T>
void write_numerical_array(const std::vector<T> &nArray)
{
typename std::vector<T>::const_iterator it = nArray.begin();
while(it!=nArray.end())
{
std::cout<<*it<<std::endl;
it++;
}
}
int main(int,char*[])
{
std::vector<int> nArray;
for(int i=0; i<10; i++)
nArray.push_back(i);
write_numerical_array ( nArray);
return 0;
}
In the above codes, the function can deal with C++ container. I was wondering whether I can write a more general function can deal with simple variables in the meantime. For example:
int main(int,char*[])
{
float value =100;
write_numerical_array(value);
return 0;
}
I tried to do it with this function, but failed:
template<typename T>
void write_numerical_array(T &nArray)
{
typename T::const_iterator it = nArray.begin();
while(it!=nArray.end())
{
std::cout<<*it<<std::endl;
it++;
}
}