Connecting Tech Pros Worldwide Forums | Help | Site Map

C++/JNI

Pradeep
Guest
 
Posts: n/a
#1: Oct 11 '05
Hi,

I have a DLL which is built in C++. This C++ DLL has a JNI Interface
and the methods are called from Java.

I want to know how to define the default / Optional parameters in C++
so that they can be called from Java.

Say for example I have a method add in C++

int add (int x = 5, int y = 10);

Can this method be called from Java through JNI by such a call

int z = object.add();

Or do i need to overload the add method in C++?

Another question I have is that can i use default values in a way such
that the next value has the optional value of the previous one
say

add( int x = 5, int y = x);

Or do i need to overload the method in this case also?

Thanks in Advance
Pradeep


Stefan Schulz
Guest
 
Posts: n/a
#2: Oct 11 '05

re: C++/JNI


On Tue, 11 Oct 2005 05:07:33 -0700, Pradeep wrote:
[color=blue]
> Hi,
>
> I have a DLL which is built in C++. This C++ DLL has a JNI Interface
> and the methods are called from Java.
>
> I want to know how to define the default / Optional parameters in C++
> so that they can be called from Java.
>
> Say for example I have a method add in C++
>
> int add (int x = 5, int y = 10);
>
> Can this method be called from Java through JNI by such a call
>
> int z = object.add();
>
> Or do i need to overload the add method in C++?[/color]

Default parameters are "syntactic sugar" offered by C++ for overloading
methods. Java does not offer this dangerous bit of candy (and i sure hope
it never will). You will need to define java methods for each intentional
mode of invocation.

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


Pete Barrett
Guest
 
Posts: n/a
#3: Oct 11 '05

re: C++/JNI


On Tue, 11 Oct 2005 20:41:22 +0200, Stefan Schulz <terra@spacetime.de>
wrote:
[color=blue]
>On Tue, 11 Oct 2005 05:07:33 -0700, Pradeep wrote:
>[color=green]
>> Hi,
>>
>> I have a DLL which is built in C++. This C++ DLL has a JNI Interface
>> and the methods are called from Java.
>>
>> I want to know how to define the default / Optional parameters in C++
>> so that they can be called from Java.
>>
>> Say for example I have a method add in C++
>>
>> int add (int x = 5, int y = 10);
>>
>> Can this method be called from Java through JNI by such a call
>>
>> int z = object.add();
>>
>> Or do i need to overload the add method in C++?[/color]
>
>Default parameters are "syntactic sugar" offered by C++ for overloading
>methods. Java does not offer this dangerous bit of candy (and i sure hope
>it never will). You will need to define java methods for each intentional
>mode of invocation.[/color]

Even in C++, I think you'll find that the substitution of the default
parameters occurs at compile time, rather than at run time, so the
actual call includes all the parameters. Since the Java program will
necessarily invoke the C++ methods at run time, the call from Java
will need to supply all the parameters.

Pete Barrett
Roedy Green
Guest
 
Posts: n/a
#4: Oct 12 '05

re: C++/JNI


On Tue, 11 Oct 2005 20:54:51 +0100, Pete Barrett
<petebarrett@beeb.net> wrote or quoted :
[color=blue]
>Even in C++, I think you'll find that the substitution of the default
>parameters occurs at compile time, rather than at run time, so the
>actual call includes all the parameters. Since the Java program will
>necessarily invoke the C++ methods at run time, the call from Java
>will need to supply all the parameters.[/color]

The equivalent feature in Java is the ability to define a method with
the same name but fewer parms. You then implement it with a call to
the many-parm method filling in defaults.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Closed Thread