Error: expected type-specifier before ‘ClassName’

For future people struggling with a similar problem, the situation is that the compiler simply cannot find the type you are using (even if your Intelisense can find it). This can be caused in many ways: You forgot to #include the header that defines it. Your inclusion guards (#ifndef BLAH_H) are defective (your #ifndef BLAH_H doesn’t match your #define BALH_H due … Read more

Difference in make_shared and normal shared_ptr in C++

The difference is that std::make_shared performs one heap-allocation, whereas calling the std::shared_ptr constructor performs two. Where do the heap-allocations happen? std::shared_ptr manages two entities: the control block (stores meta data such as ref-counts, type-erased deleter, etc) the object being managed std::make_shared performs a single heap-allocation accounting for the space necessary for both the control block and the data. In the other … Read more

When to use virtual destructors?

Virtual destructors are useful when you might potentially delete an instance of a derived class through a pointer to base class: Here, you’ll notice that I didn’t declare Base’s destructor to be virtual. Now, let’s have a look at the following snippet: Since Base’s destructor is not virtual and b is a Base* pointing to … Read more