简体   繁体   中英

How to export overloads of a function in a C++ dll??

I am looking for a way to export from my C++ dll a function with two overloads.

This is my overloads on the .h file:

static __declspec(dllexport) int __stdcall TotalCost(char* a, double* b);
static __declspec(dllexport) int __stdcall TotalCost(char* a, double* b, double c);

my questions are:

  • is it possible to export overloads of a function??
  • how I can set in the file .def the EXPORT ??

Thanks in advance Fabio

Yes, you can export overloads.

The classic way is to add the following macro definition to your library headers:

#ifdef MYLIB_EXPORTS
  #define MYLIB_API __declspec(dllexport)
#else
  #define MYLIB_API __declspec(dllimport)
  #pragma comment(lib,"MYLIB.lib")
#endif
//...

Use the above macro in your interface files:

MYLIB_API int ComputeTotal(...
class MYLIB_API C_MyClass...

You will have to define MYLIB_EXPORTS in your DLL project settings (C++/Preprocessor Definitions).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM