Witam mam problem z następującym programem zawierającym szablony funkcji znajdujących element w częściowo wypełnionej tablicy. Oto kod:
#include<iostream>
using namespace std;
const int ROZMIAR = 20;
template<class T>
void wypelnij(const T a[])
{
int j = 0;
int znak;
cout << "Wypelnij tablice, wprowadzanie zakoncz liczba ujemna\n";
while (znak > 0)
{
cin >> znak;
a[j] = znak;
j++;
}
}
template<class T>
int sprawdz(int a[], int liczba_elem, T& wartosc)
{
for(int i = 0; i < liczba_elem; i++)
{
if (a[i] == wartosc)
return a[0];
else
return -1;
}
}
int main( )
{
template<class T>
T a[ROZMIAR];
wypelnij(a);
getchar( );
return 0;
}
Gdy uruchamiam program dostaje następujące błędy:
Line In function `void wypelnij(const T*) [with T = int]':
37 instantiated from here
16 assignment of read-only location