如何为指针创建typedef

时间:2017-05-29 14:00:54

标签: c++

我正在尝试为指针创建内存。我有一个代码:

#ifdef  SOURCE_CODE_EXPORTED

static struct BasicIDymosimStruct*basicI = 0;
static struct BasicDDymosimStruct*basicD = 0;
struct BasicIDymosimStruct*getBasicIDymosimStruct() {
    return basicI;
}
struct BasicDDymosimStruct*getBasicDDymosimStruct() {
    return basicD;
}
void setBasicStruct(double*d, int*i) {
    basicI = (struct BasicIDymosimStruct*)(i);
    basicD = (struct BasicDDymosimStruct*)(d);
}
struct DymosimSimulator dataNoDll = { 0,0,"?????","?????",FALSE_ };
struct DymosimSimulator*dataNoDllPtr = 0;
#endif

对于内存分配,我正在编写如下代码:

dymBasicD = (struct *) (calloc(1, sizeof(struct BasicDDymosimStruct)));

dymBasicI = (struct *) (calloc(1, sizeof(struct BasicIDymosimStruct)));

但是,我收到错误说

  

: - C2332:无法从'*'转换为basicIDymosimStruct。

注意:我正在将此C代码与c ++混合使用。

任何想法都将不胜感激

1 个答案:

答案 0 :(得分:2)

如果您想要typedef指针,请使用C / C ++的以下语法:

typedef int* IntPointer;

对于C ++:

using IntPointer = int*;

如果要输入指向函数的指针

typedef /*return value type*/ (*t_somefunc)(/* type1 */, /* type2 etc */);