Working stack state listeners in C++