0

The following code is not completely in English but you'll get the point.

class Student : public Osoba{
    const int _brojIndeksa;
    Kolekcija<Predmet, int, 5> _polozeniPredmeti;
    vector<char*> _seminarski;      // naslovi seminarskih radova

    public:
    // constructor
    Student(char* ip, int brIndeksa) // brIndeksa is a global variable
        :Osoba(ip), _brojIndeksa(brIndeksa), _polozeniPredmeti()
    {
        cout << "Test!" << endl;
    }

The error I'm getting mentions buffer being too small.

I discovered that the issue lies in this line:

 Kolekcija<Predmet, int, 5> _polozeniPredmeti;

If I make it like this for example:

Kolekcija<int, int, 5> _polozeniPredmeti;

the program works. So this class Predmeti (school subjects) is somehow to blame:

class Predmet
{
    char* _naziv;
    char* _profesor;
    public:
    Predmet(char* naziv = "<naziv>", char* prof = "<prof>")
    {
        int size = strlen(naziv);
        _naziv = new char[size];
        strcpy_s(_naziv, size, naziv);

        size = strlen(prof);
        _profesor = new char[size];
            strcpy_s(_profesor, size, prof);
    }

I assume the default constructor of the above class is being called on Student instantiation.

Finally, the Kolekcija class looks like this (and it's been tested with built in types (int, double):

template<class T1, class T2, int max>
class Kolekcija
{
    T1* _clan1[max];
    T2* _clan2[max];
    int* _trenutnoClanova;
    public:

    Kolekcija()
    {
        cout << "pocetak" << endl;

        for (int i = 0; i < max; i++)
        {
            _clan1[i] = new T1;
            _clan2[i] = new T2;
        }
        _trenutnoClanova = new int(0);
    }

Any help will be appreciated!

developer10
  • 1,450
  • 2
  • 15
  • 31

0 Answers0