There is an array out of bounds issue and a missing delete [] in the code below.
Compiling code with the following options does not trigger any errors:
g++ -std=c++2a -Wall -pedantic -fstack-protector-all test.cpp
#include <iostream>
class Base {
public:
Base() { std::cout << "Base()\n"; }
~Base() { std::cout << "~Base()\n"; }
int m_counter;
};
class Derived: public Base {
public:
Derived() { std::cout << "Derived()\n"; }
~Derived() { std::cout << "~Derived()\n"; }
};
int main() {
Base* b = new Derived[10];
std::cout << b[10].m_counter << '\n';
delete b;
return 0;
}
Any pointers as to what I could be missing here?