Jump to content

[SOLVED] Strange behavior of vector in recursion


photo

Recommended Posts

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
Link to comment
×
×
  • Create New...