Demons implementation in C++