Extern "C", const type & fun () const

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.