Is that really so stange? It is difficult for anyone to judge from a fragment of the code. I will try to guess from the information you made available. Since your new code mentions "this" on line 1, it means that it is part of a method's body. Therefore, in your original code, server would go out of scope at the end of the execution of this method and would be destroyed, effectively shutting the server down. The control would subsequently return to the event loop to wait for incoming connections but it was too late since the server had already been destroyed. Now that the server is allocated on the heap, it is not destroyed at the end of the method and this problem disappears. Alternatively you could allocate it on the stack somewhere where it lives long enough (e.g. in main()).
It would have been useful to see the whole code from the beginning.




Reply With Quote

Bookmarks