corba - 如何在 CORBA IDL 中声明/使用对结构的前向引用?

标签 corba forward-declaration idl idlj

我有以下 CORBA IDL 3.2,它试图声明一个相互递归的结构:

module SE
{
  interface SE
  {

typedef unsigned short MenuItemID; // a small integer representing a unique menu item

enum MenuSubaction { CollectCharacter, CollectStruct };

struct MenuItemAction;   // forward declaration

union MenuSubactionParameter switch (MenuSubaction)
{  case CollectStruct:  MenuItemAction sub_structure;    // <<<<<<<<< use of forward
};

struct MenuItemAction {   MenuSubaction menu_subaction;
              MenuSubactionParameter menu_subaction_parameter;
              };
  }; // interface
}; // module

我在标有 <<<<<

的行上收到来自 Sun JDK 1.7 idlj 的投诉
 ... SE.idl (line xx): Illegal reference to incomplete forward declaration of type MenuItemAction.

注意:这不是“前向接口(interface)”声明。

什么是“不完整的前向声明”? (如果您成功声明为前向声明,我不会认为前向声明不完整,只是尚未定义。也许这只是一个容易误解的短语)。

更重要的是,我如何设法定义我的递归结构?

我是 CORBA 的新手,所以我真的不知道 :-} 我在做什么。我不明白为什么 CORBA 不能定义这样的递归结构;一个传输不会递归的特定实例。特别是,这形成了一棵树,对于 CORBA 来说应该是“容易”发送的。

编辑:Brian 的答案是正确的。我需要替换前向引用的直接提及,

         MenuItemAction sub_structure

         sequence<MenuItemAction> sub_structure>  

最佳答案

您可以转发声明结构,但有很多限制。

编辑:我不知道您使用的是哪个版本的 CORBA,但是在 2.6.1 specification 中它在第 3.10.2.3 节(强调我的)中说:

The IDL syntax allows the generation of recursive structures and unions via members that have a sequence type.

之后:

IDL supports recursive types via a forward declaration for structures and unions (as well as for valuetypes).

之后:

An incomplete type can only appear as the element type of a sequence definition. A sequence with incomplete element type is termed an incomplete sequence type.

An incomplete sequence type can appear only as the element type of another sequence, or as the member type of a structure or union definition.

例子:

struct Foo; // Forward declaration; Foo is incomplete
typedef sequence<Foo> FooSeq;  // incomplete sequence type
struct Foo {
   long value;
   FooSeq chain; // incomplete seq. type used as struct member; OK
};

可以在链接中找到更多信息,包括这个示例,它可能更接近您想要执行的操作:

union Bar; // Forward declaration
typedef sequence<Bar> BarSeq;

union Bar switch(long) { // Define incomplete union
   case 0:
      long l_mem;
   case 1:
   struct Foo {
      double d_mem;
      BarSeq nested; // OK, recurse on enclosing
                     // incomplete type
   } s_mem;
};

关于corba - 如何在 CORBA IDL 中声明/使用对结构的前向引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17256682/

相关文章:

linux - PuTTy 后台处理执行 IDL 脚本

c++ - 如果线程本身退出,则从从线程调用的方法强制返回

corba - CORBA 是遗产吗?

c++ - 当类包含在另一个类中时,为什么不转发类工作的声明

c - 为什么允许指向不完整类型的指针而不是不完整类型的变量?

c++ - 提前申报有什么危险?

java - CORBA:服务器作为客户端

java - 在 Java 中运行嵌入式 CORBA 命名服务

c++ - 如何在 C++ 中使用 IDL 来桥接系统消息

c++ - 接口(interface)的helpstring应该包含什么?