Witam
Mam problem z programem, który ma wektor(kopia vectora z stl), oraz 3 klasy: firma, sklep i produkty. Klasa firma posiada w sobie wektor sklepów, a klasa sklep posiada wektor produktów. Problem pojawia się gdy już do stworzonej pierwszej firmy i w niej pierwszego sklepu, próbuję dodać kolejny sklep. Program nie dodaje do tego wektora sklepu, jak by coś było nie tak z funkcją PushBack().
Wklejam kod wektora:
template<class T>
class Wektor{
private:
T* item;
int maxSize;
int actualSize;
void allocNew();
public:
Wektor();
Wektor(int size);
~Wektor();
Wektor(const Wektor& wektor);
void PushBack(const T& itemToPush);
void Insert(int iterator, const T& itemToPush);
void Delete(int iterator);
void Erase();
int Size() const;
T operator[](int i) const;
};
template<class T>
Wektor<T>::Wektor(){
maxSize = 3;
actualSize = 0;
item = new T[maxSize];
}
template<class T>
Wektor<T>::Wektor(int size){
maxSize = size;
actualSize = 0;
item = new T[maxSize];
}
template<class T>
Wektor<T>::~Wektor(){
delete[] item;
}
template<class T>
Wektor<T>::Wektor(const Wektor& wektor){
}
template<class T>
void Wektor<T>::PushBack(const T& itemToPush){
if (actualSize + 1 > maxSize)
allocNew();
item[actualSize] = itemToPush;
actualSize++;
}
template<class T>
T Wektor<T>::operator[](int i) const{
return item[i];
}
template<class T>
void Wektor<T>::allocNew(){
maxSize = actualSize * 2;
T* temp = new T[maxSize];
for (int i = 0; i < actualSize; i++)
{
temp[i] = item[i];
}
delete[] item;
item = temp;
}
template<class T>
int Wektor<T>::Size() const{
return actualSize;
}
template<class T>
void Wektor<T>::Insert(int iterator, const T& itemToPush){
if (actualSize + 1 > maxSize)
allocNew();
for (int i = (actualSize - 1); i >= (iterator - 1); i--)
{
item[i + 1] = item[i];
}
item[iterator - 1] = itemToPush;
actualSize++;
}
template<class T>
void Wektor<T>::Delete(int iterator){
for (int i = iterator; i < actualSize; i++)
{
item[i - 1] = item[i];
}
actualSize--;
}
template<class T>
void Wektor<T>::Erase(){
delete[] item;
item = new T[maxSize];
actualSize = 0;
}
Header klasy firma:
class Firma{
public:
Wektor<Sklep> sklepy;
Firma(){}
Firma(string nFirmy, string uSklepu);
Firma(const Firma& firma);
void Wypisz();
void DodajSklep(string ulica);
string nazwaFirmy;
Firma& operator=(const Firma& firma);
};
Kod z maina:
Wektor<Firma> wektor;
string nazwaFirmy = "adidas";
string ulicaSklepu = "warszawska";
Firma firma(nazwaFirmy, ulicaSklepu);
wektor.PushBack(firma);
wektor[0].sklepy.PushBack(*new Sklep("poznanska"));
wektor[0].Wypisz();
Program wypisuje tylko "adidas warszawska", natomiast "poznanska" już nie. Dodam jeszcze, że gdy użyłem vector z stl to działał program poprawnie. Próbowałem debugować program, dziwna sytuacja, gdy próbuję dodać poznanska, wywołuje się domyślny konstruktor wektora, co mnie całkowicie dziwi. Proszę o pomoc