I started to write a text game for university task and realized that i cant create an child object from the constructor. The application just closes without prompting. I've tried to find some examples in the net... this code do the same thing in DevC++
# include <iostream.h>
# include <conio.h>
# include <process.h>
class tri_num
{
int f;
public :
tri_num( ) { f=0; }
void sum( int j) { f=f+j; }
tri_num(int m){
if (m==0) {
cout <<"Triangular number : "<<f;
exit(1);
};
sum(m);
tri_num::tri_num(--m);
}
};
int main()
{
//tri_num::tri_num(5); //Also doesn't work
tri_num* a= new tri_num(5);
getche();
}
Well I found that it exits in first recursive call.
This was just a code i found as recursive example.
I didn' posted my code.
I'm working on getting rid of recursivity in my program.
I made an init method that finishes everything constructor should do. Hope that would work.
It does not exit in first recursive call in my debugger. It cannot - since in fist call you pass m=5, and in next recursion it can only be 4, no less, hence not 0.