April 2020
Intermediate to advanced
412 pages
9h 58m
English
We will create a custom class that allocates a specified amount of memory and statically allocates two instances of the class. Follow these steps:
#include <iostream>#include <stdint.h> class Complex { char* ptr; public: Complex(size_t size) noexcept { try { ptr = new(std::nothrow) char[size]; if (ptr) { std::cout << "Successfully allocated " << size << " bytes" << std::endl; } else { std::cout << "Failed to allocate " << size << " bytes" << std::endl; ...Read now
Unlock full access