IDK what the hell happened but this code
void push_back(const T& elem) {
try {
if (capacity <= size) {
auto newData = normalize_capacity();
std::memcpy(newData, data, size * sizeof(T));
if (data != nullptr && newData != data) {
free(data);
}
data = newData;
}
data[size] = elem;
++size;
}
catch (...) {
std::cerr << "Something happened in push_back" << std::endl;
throw;
}
}
with this
T* normalize_capacity() {
while (capacity <= size) {
capacity *= 2;
}
T* newData = (T*)malloc(sizeof(T) * capacity);
if (!newData) {
throw std::bad_alloc();
}
if (data) {
std::memcpy(newData, data, size * sizeof(T));
}
return newData;
}
actually worked thank you guys for all of the help and advises!