C++ function overloading in harbour wrapper function not working

84 views
Skip to first unread message

Reinaldo Crespo

unread,
May 23, 2023, 12:47:48 PM5/23/23
to Harbour Developers
Hello Harbour!

I'm trying to write some c wrappers for harbour VM and attempting to use function overloading.    

In C++, you can achieve function overloading by declaring multiple functions with the same name but different parameter lists. 

However, when compiling my .prg that includes c code inside #pragma BEGINDUMP, Harbour reports declaration syntax error when I try to implement function overloading.   Here is some sample code:

HB_BOOL OCRWait(long JobNo, TOCRJOBINFO2 JobInfo2);
BH_BOOL OCRWait(long JobNo, TOCRJOBINFO_EG JobInfoEg);

On these two lines  the compiler errors:
Type mismatch in redeclaration of OCRWait
Earlier declaration of 'OCRWait'

Also, why can't I just declare these c functions as "bool" if I'm only calling them from inside other c++ code and not directly from Harbour code?

Can someone here help?

Thank you.

Bacco

unread,
May 23, 2023, 1:15:24 PM5/23/23
to harbou...@googlegroups.com
Why don't you simply create a separated C++ file for your wrapper and
compile together instead of BEGINDUMP?
You can't use name mangling this way in C.

As it's not a bug in Harbour itself, I believe this should be posted on users group, not the development one:


Regards,
Bacco


--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/3cd56a1c-c4d9-450e-b8e8-42af37ccb0ben%40googlegroups.com.

Reinaldo Crespo

unread,
May 23, 2023, 4:36:24 PM5/23/23
to Harbour Developers
Ok, Bacco.  I will do so.
TY.

Francesco Perillo

unread,
May 23, 2023, 4:49:04 PM5/23/23
to harbou...@googlegroups.com
You are using c++ syntax where the language used is c...

C doesn't support function overloading.

So.... 

You may try to put these functions in a external .cpp file that hbmk2, recognizing the .cpp, will compile as c++.




Reinaldo Crespo

unread,
May 23, 2023, 4:57:57 PM5/23/23
to Harbour Developers
Francesco,  that's an answer that makes sense and helps me understand what's happening.   One always wishes for that type of answers when posting on forums.

Thank you,

Reply all
Reply to author
Forward
0 new messages