调用尚未定义的类型 [英] Calling a Type that is not yet defined

查看:69
本文介绍了调用尚未定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,感谢您的阅读.

我处于一个难题中,我需要调用在动态创建的文件中声明的数据类型.

我有一个从WSDL文件动态创建的H文件,它包含从客户端到主服务器的gSOAP通信的结构定义.

现在,我必须在使用H文件中的一种类型的Library进程中实现一个新的SOAP API调用,但是动态创建H文件是在编译Libraries之后(新调用位于其中).

必须先编译库,然后程序的其余部分才能正常工作.

这给我带来了一个问题,即引用一个不仅未定义的数据类型,而且还没有定义该数据类型的文件,而且我无法首先创建该文件,因为它需要库来编译该部分. />
1)我是否可以使用Extern或类似方法说服编译器不报告不完整的类型且无法定义"错误并进行编译?

2)如果没有,我是否需要更改构建顺序?

3)我在做这种事情时不正确吗?

谢谢

Firstly, thanks for reading.

I am in a conundrum, I need to call a data type which is declared in a file that is dynamically created.

I have a H file that is created dynamically from a WSDL file, it contains structure definitions for gSOAP communication from my client to the main server.

I now have to implement a new SOAP API call from within a Library process that uses one of the types in the H file, but the dynamic creation of the H file is after the compilation of the Libraries (which the new call is in).

The Libraries need to be compiled first for the rest of the program to work.

Which creates for me the problem of referencing a data type that is not only not defined, but the file in which it is defined does not exist yet, and I cannot create the file first as it requires the Libraries to compile that section.

1) Is there a way for me to use Extern or something similar to convince the compiler to not report a "incomplete type and cannot be defined" error and compile?

2) If not, do I need to change my build order somewhat?

3) Am I not doing something right to reach such a situation?

Thanks

推荐答案

无论如何,您都必须知道接收到的数据的结构.它可以是预定义的,也可以用SOAP结构描述.

在某些情况下,函数以可以返回任何内容,数组的指针或结构的指针甚至长值的方式编写.例如,GetWindowLong函数返回long,它可以是指针或long值.但是无论何时使用它们,都必须知道您要接收的内容.
No matter what, you must have to know the structure of your received data. It can be predefined or it can be described in SOAP structure.

In some cases function is written in such a way that it can return anything, pointer of array or pointer of structure or even long value. as example GetWindowLong function returns long, it can be a pointer or a long value. But whenever you will use them you must have to know what are you receiving.


1.您无法编译不完整的代码,因此必须在开始编译之前提供完整的类定义.

2.如果遵守以下两个规则,则可以仅使用前向声明来编译部分代码:
a)您必须知道类的确切名称(以进行前向声明)
b)您可能无法访问该类的任何成员,并且只能访问指向类类型的指针或对类类型变量的引用-以任何方式创建实例都需要该类的完整代码,因此您只能不再需要指针和引用了.

3.很可能您做错了.但是,如果没有更多信息,我们就无法告诉您为什么需要动态创建类型以及需要使用该类型做什么.无论如何,如果要访问该类的函数,则必须至少至少知道该点的函数定义,因此也必须具有该类的定义. OTOH如果您没有功能,那么您根本不需要一个(动态创建的)类,只需一个动态数据结构即可,并且可以通过其他方式处理.

您真正的难题是,您暗示您的代码可以明智地访问它不知道任何内容的类型(或类),但是如果您当时没有定义,它怎么能甚至引用该类/类型或其成员呢?写代码?您必须已经具有关于该类/类型的结构和设计的一些知识,以便能够编写访问该类/类型的代码,因此它不可能完全是动态的.
1. You cannot compile incomplete code, therefore you must provide the full class definition before starting the compilation.

2. You can compile parts of your code with just a forward declaration if it abides by two rules:
a) you must know the exact name of the class (to make the forward declaration)
b) you may not access any members of the class, and you can only access pointer to class-type or reference to class-type variables - to create an instance in any way would require the full code of the class, so you can only shove around pointers and references, no more.

3. Most likely you''re doing it wrong. But we can''t tell without further information about why you need to dynamically create a type, and what you need to do with it. In any case, if you want to access functions of that class you must at the very least know the function definitions at that point, so you must have the class definition as well. OTOH if you don''t have functions, then you don''t need a (dynamically created) class at all, just a dynamic data structure - and that can be dealt with in other ways.

Your real conundrun is that you imply your code can sensibly access a type (or class) it doesn''t know anything of - but how can it even refer to that class/type or members thereof if there is no definition at the time you write the code? You must already have some knowledge about the structure and design of that class/type just to be able to write that code that accesses it, so it cannot possibly be entirely dynamic.


这篇关于调用尚未定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆