Search the Community
Showing results for tags 'recursion'.
-
Hello Short example: class T { string a; T(string value) { a = value; } }; class My { int _flag = 0; int _test[0]; T _test2 = new T("old"); void test() { log.message("before:\t" + string(_test.size()) + "\t" + _test2.a + "\n"); int local[] = (1); T local2 = new T("temp"); log.message("after:\t" + string(_test.size()) + "\t" + _test2.a + "\n"); local.append(10); _test = local; local2 = new T("new"); _test2 = local2; if (_flag == 0) { _flag = 1; test(); } } } Expected: before: 0 old after: 0 old before: 2 new after: 2 new Real result: before: 0 old after: 0 old before: 2 new after: 1 new
-
So, I have a recursive class function with a map, a vector, and a problem Say the function looks like void foo(MyObject bar) { *do stuff with bar* MyObject childObjectMap[]; bar.getChildren(childObjectMap); // clears childObjectMap then copies all of the child objects into it foreach(MyObject obj; childObjectMap) { foo(obj); } } The expected result is that this will traverse each MyObject, do things with it, then get all it's children objects and repeat recursively. What actually happens is that it only does this with the first child. So, even if each MyObject has five children this will only recurse on the first child of the first child. What I found is happening is that each time the ID of ChildObjectMap remains the same so, in essense, it is static. Everytime I call MyObject::getChildren I'm clobbering it so on the return it has the data from the child. So, the question becomes, how do I create a new map or vector to keep a function from treating a map or vector like a static?