Szablon - tablica

0

Witam,

mam problem w programie:

#include <iostream>
using namespace std;




template <typename T, int N=5>


class Tablica {

    T tab[N];

public:

/* Metoda get */
    bool get (int i, T& t){
        if(i<=0 || i>=N)
            return false;
        t=tab[i];
        return true;
    }
/* Metoda set */

        if( i<=0 || i>=N )
            return false;
        tab[i]= t;
    }

    T& operator[](int i){
        if ( i<0 || i>=N )
            throw i;
        return tab[i];
    }

    int find(T& t){
        for ( int i=0; i<N; i++)
            if(tab[i] == t)
                return 1;
        return -1;
    }
};


int main()
{

    Tablica<char, 10> tc;

    tc.set(0, 'A');
    char c;

    if(tc.get(0, c))
        cout <<"znak: " << c << endl;
    if(tc.get(10, c))
        cout << "znak: " << c << endl;
    else
        cout<< "Error" << c << endl;
    tc[5] = '5';

    cout << "Operator[]: " << tc[5] << endl;
    cout << "i: " << tc.find('5') << endl;
    return 0;
}

Wyrzuca blad na find, drugi blad przy get powinnien wyswietlic setowany znak a wyswietla Error.

1
    bool get (int i, T& t){
        if(i<=0 || i>=N)
            return false;
        t=tab[i];
        return true;
    }
/* Metoda set */
 
        if( i<=0 || i>=N )
            return false;
        tab[i]= t;
    }

Przypatrz sie uwaznie... (chyba, ze slepne na starosc, wtedy prosilbym o sprostowanie).

  • Jesli mam racje to kompiler powinien cala litanie tych bledow wypluc, dlaczego ich nie wrzuciles?

1 użytkowników online, w tym zalogowanych: 0, gości: 1