Home > Back-end >  After the compilation, using g global object constructor does not perform
After the compilation, using g global object constructor does not perform

Time:11-19

Global object is not initialized before the main function,
In the call after the global object to perform the constructor

For example:
 
The class testclass
{
Public:
Testclass ()
{
Dbg_print (" new testclass ");
}
Void test ()
{
Dbg_print (" test ");
}
};
Testclass tac.
Int main ()
{
The (tac);
}

Results output:
The test
New testclass

Hope to have bosses can help to solve

CodePudding user response:

You the results of this example is absolutely new tastclass before, and it can't be you the output results

CodePudding user response:

Code is too little, where another global object initialization?

CodePudding user response:

I tested right

CodePudding user response:

This has to do with DBG you?
If use the standard input input without any problem,

CodePudding user response:


CodePudding user response:

This is just a simple example, I'm in the middle of development projects in this situation, using the GDB breakpoint debugging, measured is, indeed, I said that as a result, a member function to perform first, the object initialized again, very strange

CodePudding user response:

The platform is ubuntu 20.04

CodePudding user response:

There should be no correct output cause you don't think object structure, secretly tell you have a way to test object structure success:
 class testclass 
{
Public:
Testclass () : I (100)
{
Dbg_print (" new testclass ");
}
Void test ()
{
Dbg_print (" test ");//the value of the output I here if there is no object structure, output will be an error, I
}
Private:
int i;
};
Testclass tac.
Int main ()
{
The (tac);
}

CodePudding user response:

 # include & lt; Stdio. H> 
The class testclass
{
Public:
Testclass ()
{
Printf (" % d % s: % - 4 p new testclass \ n ", a __FILE__ and __LINE__, this);
}
Void test ()
{
Printf (" % s: % - the 4 d % p test \ n ", a __FILE__ and __LINE__, this);
}
};
Testclass tac.
Int main ()
{
The (tac);
return 0;
}
//test. The CPP: 7 00 a93374 new testclass
//test. The CPP: 11 00 a93374 test

With the above method to determine the output is the same period of the source code of the same class instance?

CodePudding user response:

The eighth floor of the method is right, you simply measure not to come out, in the main function in the construction of class directly output to go,
  • Related