devxlogo

Executing a Member Function Before main()

Executing a Member Function Before main()

We can execute any member function or any other execution before main() function by using:

        "#pragma startup".Syntax:      #pragma startup  [priority]//without semicolon

Example:

 #includeclass CL{public:	//A constructor	CL(){	cout  "
The object is creating"; }	//A member function	void obj_func() { cout  "
This is a function of object"; }};void func_before_main ();	//function declaration#pragma startup func_before_main 65	//setting a function to execute beforemain()void main (){  cout 

In defining such functions, the functions should not carry any attributenor return any value. It should be defined before #pragma statement.
Priority is optional. It is ranging from 64 to 100 (recomended).
0-------Highest priority used by C Libraries
63------Lowest priority used by C Libraries
64------First available Priority
100-----Default priority
255-----Lowest priority.

devx-admin

Share the Post: