Question: How can I instrument C++ code such that I can get the object count per class at runtime?

I could overload the new and delete operators, implement custom constructors/destructors, but I am looking for a generic approach that does not require altering all classes in my code.

Answer: 
One way is to have a static `count` member on the class. You would have to increment it each time a constructor is called, and decrement when destructor is called.

E.g.

```
class SomeClass {
  private:
    static uint64_t count;

  public:
    SomeClass() {
        ++count;
    }
    ~SomeClass() {
        --count;
    }
};

// Initialize count
uint64_t SomeClass::count = 0;

```
Instead of overloading you could try defining a macro which redefines all the new keywords in the entire project.

```
#define new (some code to create and log)

```