Dynamic class implemented in C++