我必须使用idlj作为我的学校项目,但在我的idl文件中,我也需要使用前向声明。有谁知道idlj是否支持前瞻性声明?我试过这样做,但它会产生错误:
interface1.idl (第34行):有一个对Class1的前向引用,但没有定义它。
有什么办法克服这个问题吗?我不能使用任何其他idl编译器,不幸的是.我找不到关于这件事的任何信息。
编辑:
接口1.idl:
interface SecondClass;
interface FirstClass
{
//...
};接口2.idl:
interface FirstClass;
interface SecondClass
{
//...
};idlj -fclient接口1.idl
给予:
interface1.idl (第8行):有一个对SecondClass的前向引用,但没有定义它。};^
发布于 2012-08-23 21:49:51
这个版本的代码终于起作用了(编译时没有错误),但我仍然不知道如何和为什么;P
我不知道它是如何编译的,也不知道为什么,但它最终没有错误地编译,请看一看:
文件接口1.idl
#ifndef __FIRSTCLASS_IDL__
#define __FIRSTCLASS_IDL__
#include "interface2.idl"
interface FirstClass
{
typedef sequence<SecondClass> secondVector;
FirstClass create();
};
#endif文件接口2.idl
#ifndef __SECONDCLASS_IDL__
#define __SECONDCLASS_IDL__
interface FirstClass;
interface SecondClass
{
typedef sequence<FirstClass> firstVector;
SecondClass create();
};
#include "interface1.idl"
#endif我只是有点困惑,为什么一个include指令位于idl文件的顶部,而另一个必须位于底层。有人知道吗?天哪!
发布于 2012-08-23 21:51:02
#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。对所有相互依赖的接口使用此模式。
发布于 2012-08-23 16:45:06
我不熟悉那个球体,但它应该是可能的。请记住,如果您转发声明一个类,您最终必须在某个地方提供定义,以便翻译人员知道该做什么。
例如:
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 filehttps://stackoverflow.com/questions/12017191
复制相似问题