1. Use extern "c" and dllexport together
Library Project globaltest. hCodeAs follows:
# Ifdef globaltest_exports
# Define gt_export _ declspec (dllexport)
# Else
# Define gt_export _ declspec (dllimport)
# Endif
NamespaceTT
{
Extern "C"Gt_exportVoidFatalerr (Void);
}
. Cpp
# Include " Globalmethod. h "
# Include<Iostream>
Using NamespaceTT;
VoidGt_export fatalerr (Void)
{
Printf ("Fatal error: \ n");
//Exit (0 );
}
Main. cpp of the Application Project
# Pragma Comment (Lib, "globaltest. lib ")
# Include " ../Globaltest/globalmethod. h "
# Include<Iostream>
Using NamespaceTT;
IntMain ()
{
Fatalerr ();
System ("Pause");
Return 0;
}
In this case, a connection error is reported.
Main. OBJ: Error lnk2019: external symbol that cannot be parsed _ imp _ fatalerr, which is referenced in function _ main
If namespace is not used, no. Puzzled.
2. Const type & fun () const and type & fun (). They are used very well and have no notes. (Pay attention to the const pointer when using it)