gpt4 book ai didi

c++ - 如何实例化架构对象?

转载 作者:行者123 更新时间:2023-11-30 03:38:43 26 4
gpt4 key购买 nike

例如,我有一个模式结构

class sw_Type
{
char *Id; /* required attribute */
struct soap *soap; /* transient */
};

我创建这个对象使用

soap_instantiate__sw_Type(....)

但我不明白如何分配 char 条目。我想我应该找到一个接受返回 char *soap 的例程。我应该使用 Id = (char *) (soap_malloc(_soapInst, sz * sizeof(char) ))

如果 Idchar **,我将如何做类似的分配?

最佳答案

你应该简单地按照下面的方式做,并使用一个定义字符数组的长度。

char * Id = (char *)soap_malloc(soap, ID_LEN);

无需在您的示例中使用 sizeof。但是如果你想分配一个对象列表,那么你应该使用 Nof items x sizeof(struct ..)

关于char**,你可以使用类似下面的例子

char** arguments_push = (char**) soap_malloc(soap, sizeof(char*)*ARGS_NUM);

关于c++ - 如何实例化架构对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39351189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com