我必须使用 idlj 作为我的学校项目,但在我的idl文件中我还需要使用前向声明。有谁知道idlj是否支持前向声明?我试图这样做,但它会出错:
interface1.idl(第34行):有一个对Class1的前向引用,但是 它没有定义。
任何想法如何克服这一点?不幸的是,我不能使用任何其他idl编译器......而且我找不到任何关于此的信息。
修改
interface1.idl:
interface SecondClass;
interface FirstClass
{
//...
};
interface2.idl:
interface FirstClass;
interface SecondClass
{
//...
};
idlj -fclient interface1.idl
给出:
interface1.idl(第8行):有一个对SecondClass的前向引用, 但它没有定义。 }; ^
答案 0 :(得分:2)
#ifndef _SecondClass
#define _SecondClass
#include "interface1.idl"
interface SecondClass
{
typedef sequence<FirstClass> firstVector;
SecondClass create();
};
#endif
#ifndef _FirstClass
#define _FirstClass
#include "interface2.idl"
interface FirstClass
{
typedef sequence<SecondClass> secondVector;
FirstClass create();
};
#endif
看看this。将此模式用于所有相互依赖的接口。
答案 1 :(得分:1)
我对ORB并不熟悉,但它应该是可能的。请记住,如果你转发声明一个类,你必须最终在某个地方提供定义,以便翻译知道该怎么做。
例如:
interface SecondClass; // forward declaration
interface FirstClass {
SecondClass foo();
};
// now you must provide the IDL for SecondClass;
// either write it out here or #include the appropriate IDL file
答案 2 :(得分:0)
我的代码的最后版本(最终编译没有错误)但我仍然不知道如何以及为什么; P
我不知道如何以及为什么但最终编译时没有错误,请看一下:
文件interface1.idl
#ifndef __FIRSTCLASS_IDL__
#define __FIRSTCLASS_IDL__
#include "interface2.idl"
interface FirstClass
{
typedef sequence<SecondClass> secondVector;
FirstClass create();
};
#endif
文件interface2.idl
#ifndef __SECONDCLASS_IDL__
#define __SECONDCLASS_IDL__
interface FirstClass;
interface SecondClass
{
typedef sequence<FirstClass> firstVector;
SecondClass create();
};
#include "interface1.idl"
#endif
我有点困惑为什么一个include
指令位于idl文件的顶部,而另一个指令必须位于底部。有人知道吗?吉兹!