Did you guys find the answer ? ok this may not be useful for you but I think sometimes ago I was trying to achieve "Reflection" in C++. I noticed something strange through some of the examples, it was the way a particular line of code has to be written for it to run before the main...
if you don't use static then the code won't compile..btw how do you call a function right after main..becuase main is the point your program will be starting and after main ends the program ends..so guess..I don't have a answer to that..it does appear to be calling after main but it calls myfunc() twice before entering main...We can call static functions or global functions but it *has* to return something and we need to put it in a static variable....if anyone can explain why we need to do this..that would be great...i just know it works this way..
#include<iostream>
using namespace std;
int myfunc()
{
cout<<"hello world"<<endl;
return 1;
}
class myClass{
public:
static int func(){ cout << "Inside static function"<<endl;
return 1;
}
myClass(){ cout<<"inside my class constructor"<<endl; }
~myClass();
};
static int s = myClass::func();
static int n = myfunc();
int main(int argc,char** argv)
{
cout << "inside main"<<endl;
return 0;
}
static int g = myfunc();
However, I actually don't have much idea about the seg faults that you guys are talking about....
Bookmarks