C++ 序列化定义未知的结构

C++ 序列化定义未知的结构,c++,serialization,struct,deserialization,geos,C++,Serialization,Struct,Deserialization,Geos,我在我的软件中使用geos库作为几何引擎。我目前正在使用它的capi(因为这是推荐的api) 现在的问题是我想序列化和反序列化结构几何体。库本身是C++的,CAPI是它周围的包装器。因此,结构定义不可用。我有什么选择 这就是capi提到的 /* When we're included by geos_c.cpp, those are #defined to the original * JTS definitions via preprocessor. We don't touch them t

我在我的软件中使用geos库作为几何引擎。我目前正在使用它的capi(因为这是推荐的api)

现在的问题是我想序列化和反序列化结构几何体。库本身是C++的,CAPI是它周围的包装器。因此,结构定义不可用。我有什么选择

这就是capi提到的

/* When we're included by geos_c.cpp, those are #defined to the original
* JTS definitions via preprocessor. We don't touch them to allow the
* compiler to cross-check the declarations. However, for all "normal"
* C-API users, we need to define them as "opaque" struct pointers, as
* those clients don't have access to the original C++ headers, by design.
*/
#ifndef GEOSGeometry
typedef struct GEOSGeom_t GEOSGeometry;
这就是它的包装方式

// Some extra magic to make type declarations in geos_c.h work - 
// for cross-checking of types in header.
#define GEOSGeometry geos::geom::Geometry

非常感谢您的帮助。

首先,如果您确实无法访问源文件中的
结构的定义,我会尝试使用C++11
type\u traits
类来检查它,例如
is\u pod
is\u trial
is\u standard\u layou

这样,你就可以知道你在处理什么。如果您看到
struct
非常简单,您可以“希望”它将所有数据存储在自身内部,即不指向其他内存区域。遗憾的是,据我所知,无法确定类是否有成员指针


最终,您所能做的就是尝试将其序列化,并将其残酷地写入您的输出
sizeof(GEOSGeometry)
bytes(
char
s)。然后把它读回来。。。祝你好运

在命名空间geom中查找命名空间geos。或者,通过任何接口进行功能序列化。评论说它向cpp用户公开,找到它。它是一个类。看来我将不得不使用C++ API之后。谢谢。结构根本不是结构。结果是一门课。编译器无法确定sizeof(GEOSGeometry),因为它的定义不完整。我想我必须使用C++ API并序列化类。不幸的是!