#include <iostream>
#include <string>
#include <cstring> //std::memcpy

class CustomClass
{
private:
	std::string a;
	std::string b;
public:
	CustomClass(std::string a, std::string b): a(a), b(b) {}
	std::string to_string()
	{
		return a + " of " + b;
	}
};

class CustomArray
{
private:

	CustomClass **arr = nullptr;
	size_t capacity = 0;
	size_t size = 0;


public:

	void resize(size_t new_capacity) 
	{
		CustomClass** resized_arr = new CustomClass*[new_capacity]();
		std::memcpy(resized_arr, arr, capacity * sizeof(CustomClass*));

		delete[] arr;

		capacity = new_capacity;
		arr = resized_arr;

	}
	void add(CustomClass* cc)
	{
		if (size <= capacity)
			this->resize(capacity + 1);

		arr[size++] = cc;
	}

	void print() 
	{
		for (size_t i = 0; i < capacity; i++) 
		{
			if (arr[i] == nullptr) 
				std::cout << "KEY: " << i << ", VAL: NULL" << std::endl;
			else
				std::cout << "KEY: " << i << ", VAL: " << arr[i]->to_string() << std::endl;
		}
		
		std::cout << std::endl;
	}
};



int main()
{
	CustomArray arr;
	arr.print(); // nothing
	
	CustomClass cc1("1", "3");
	arr.add(&cc1);
	CustomClass cc2("2", "3");
	arr.add(&cc2);
	CustomClass cc3("3", "3");
	arr.add(&cc3);
	arr.print(); // prints 3 elements

	arr.resize(5);
	arr.print(); //prints 2 nore NULLs


	return 0;
}