If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
The loop just doesn't work this way. The first parameter to GetFirstChild/GetNextChild must remain the same, but with "child = tv->GetNextChild(child, cookie);" you immediately change it.
Check the method "GetItemsRecursively" from the "treectrl" sample which shows how it works.