Cześć wszystkim. Jako, że jestem nowym użytkownikiem bądźcie wyrozumiali:)
Zacząłem się bawić trochę wskaźnikami, a bardziej tablicami dynamicznymi i mam teraz mały kłopot, otóż gdy chcę usunąć wskaźnik do starej tablicy i podstawić nowy to program się zawiesza. Zapewne coś źle przypisuję ale nie jestem tego świadom. Więc proszę o małą pomoc, jakieś nakierowanie.
Oto kod:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct Student{
string imie = "";
string nazwisko = "";
int wiek = 0;
int indeks = 0;
};
void add(string imie, string nazwisko, int wiek, int indeks, Student *&students, int &size){
Student * tempTab;
Student temp;
temp.imie = imie;
temp.nazwisko = nazwisko;
temp.wiek = wiek;
temp.indeks = indeks;
if (size != 0){
tempTab = new Student[size + 1];
for (int i = 0; i < size; i++){
tempTab[i] = students[i];
}
tempTab[size++] = temp;
delete[] students;
students = tempTab;
}
else{
students[size++] = temp;
}
}
int main() {
Student * students;
int size = 0;
students = new Student[1];
add("Marek", "Fujarek", 21, 205067, students, size);
add("Mateusz", "Jakiś", 31, 283945, students, size);
cout << students[0].imie << "\n";
}
```cpp