【问题标题】:Why do CORBA interfaces have a return type and an out keyword?为什么 CORBA 接口有返回类型和 out 关键字?
【发布时间】:2015-10-22 16:07:57
【问题描述】:

I was reading about CORBA 我注意到了一些有趣的事情。 CORBA 接口方法用返回类型定义,例如string in

module HelloApp
{
  interface Hello
  {
  string sayHello();
  oneway void shutdown();
  };
};

并且还有一个关键字out,当作为参数传递时,意味着返回值。 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);
};

似乎是多余的。 为什么两者都需要?

【问题讨论】:

    标签: rpc corba idl


    【解决方案1】:

    一个操作只能有一个返回值,但可以有多个个参数。这是用户决定使用什么,但在很多情况下,操作返回一个值,然后用户更容易获得返回值,以便他可以编写例如(使用 IDL 到 C++11):

    int32_t my_result = foo->my_operation ();
    

    他必须在哪里写出论据

    int32_t my_result {};
    foo->my_operation (my_result);
    

    第一个例子更简单也更安全,不需要显式初始化 my_result 为其默认值。

    【讨论】:

      猜你喜欢
      • 2010-09-28
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      相关资源
      最近更新 更多