Hey friends... Long time didnt use forum... But now i got a fairly interesting thing to get solved.
Just a few moments ago i was just doing foolish things in c++ and discovered something new. Though some of you might have known this, for those who dont know, take a look at the follwing 2 small programs,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream.h>
#include <conio.h>
void main();
void loop()
{
cout<<"calling main..."<<endl;
getch();
main();
}
void main()
{
cout<<"calling loop..."<<endl;
getch();
loop();
}
|
here you can see, i declared main 'cause have to call it in loop and actually can call main from another function... though it is wierd, it works and pretty logical... like having a mirror in front of a mirror... now take a look at this...
1 2 3 4 5 6 7 8
|
#include <iostream.h>
#include <conio.h>
void main()
{
cout<<"calling main()"<<endl;
getch();
main();
}
|
here you can see that, in general, a function can call itself during its run and main() is no exception...
Now having given some unusual intro, let me give my exact problem now...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream.h>
#include <conio.h>
class vector
{
int i,j,k;
public:
void main();
}
void vector::main()
{
cout<<"main of class..."<<endl;
getch();
main();
}
void main()
{
vector A;
cout<<"main as usual..."<<endl;
getch();
A.main();
}
|
so here is my problem. i think u wud have figured out what m trying to do above. am actually calling the main() of the class and from there, i want to call the usual main... the problem is, during A.main()'s run, if i refer to main(); , that call represents itself, that it, it is like it calls itself. How on earth can i call the outside main?? And please explain ur answers, because am a beginner. thanx in advance! :)