So I have this code which prints out an array.
This version does not work:
Code:
#include <iostream>
using namespace std;
template <size_t X, size_t Y, class T>
void func(T (&arr)[X][Y]);
int main()
{
int A[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
func(A);
return 0;
}
void func(T (&arr)[X][Y])
{
cout << X << "x" << Y << endl;
for (int i=0;i<X;i++) {
cout << endl;
for (int j=0;j<Y;j++) {
cout << arr[i][j] << "\t";
}
}
}
While this version does:
Code:
#include <iostream>
using namespace std;
template <size_t X, size_t Y, class T>
void func(T (&arr)[X][Y])
{
cout << X << "x" << Y << endl;
for (int i=0;i<X;i++) {
cout << endl;
for (int j=0;j<Y;j++) {
cout << arr[i][j] << "\t";
}
}
}
int main()
{
int A[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
func(A);
return 0;
}
Why does it not allow me to declare the function before its definition and how could I make that function accept only certain data types?