1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
template<class T>
void print(const T& c) {
for(auto n : c)
std::cout << n << ' ';
std::cout << '\n';
}
template<class T>
void print(T* p, int n) {
for(int i = 0; i != n; ++i)
std::cout << p[i] << ' ';
std::cout << '\n';
}
int main() {
int a[10] = {1,2,3,4,5,6,7,8,9,0};
int (*pa)[10] = &a;
// prints the array, because array size is not lost, guaranteed to be correct
print(*pa);
int *p = a;
// size is lost, needs to be supplied by hand (and it's impossible to verify that what you supplied is correct!)
print(p, 10);
}
|