RAII in C++

template <typename T, std::size_t N>
T* allocateMemory()
{
return new T[N];
}
template <typename T>
void freeMemory(T *p)
{
delete[] p;
}
int main()
{
int *p = allocateMemory<int, 10>();
// use p
freeMemory(p);

return 0;
}
  1. allocateMemory() is not…

--

--

--

C++11/14, Qt, Juce

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why Automate Tests and Where to Start ? ~ Part-1

Space to connect

How to set up ssh key pair with ubuntu

A case study of contributing to a Terraform Provider

Outsourcing Version 1: Advice from a CTO

Python collections:

Chapter 7 Attorney

chapter 7 attorney

Playing with Smartpy Smart Contracts: Part 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Asit Dhal

Asit Dhal

C++11/14, Qt, Juce

More from Medium

Difference between static and dynamic library

BINARY HEAPS (with code in C++)

A Max-Heap example. Notice that it is a complete tree and parents’ keys are larger than children’s keys.

Idiomatic Event Loop in C++

Hello,I’m a computer thread