Reputation: 23322
I was reading about CORBA and I noticed something funny. CORBA interface methods are defined with a return type, for example string
in
module HelloApp
{
interface Hello
{
string sayHello();
oneway void shutdown();
};
};
and also has a keyword out
which when passed as a parameter, means that value is returned. For example here
struct Data { ... };
typedef sequence<Data> DataSeq;
interface DataIterator {
DataSeq next_n_items(in unsigned long how_many);
void destroy();
};
interface SearchEngine {
DataSeq query(
in string search_condition,
in unsigned long how_many,
out DataSeq results,
out DataIterator iter);
};
Seems redundant. Why do you need both?
Upvotes: 0
Views: 310
Reputation: 3002
An operation can only have one return value, but can have a multiple out arguments. It is a user decision what to use, but in a lot of cases an operation returns one value and then it is easier for the user to have a return value so that he can write for example (using IDL to C++11):
int32_t my_result = foo->my_operation ();
Where with an out argument he has to write
int32_t my_result {};
foo->my_operation (my_result);
The first example is easier and also safer, no need to explicitly initialize my_result to its default value.
Upvotes: 1