gpt4 book ai didi

c++ - 错误 : request for member (maybe you meant to use '->' ? ) 已经使用 '->'

转载 作者:太空狗 更新时间:2023-10-29 19:59:11 25 4
gpt4 key购买 nike

对于此错误的含义是否有简单的解释?

error: request for member 'Attributes' in '* printerInfo', which is of pointer type 'PPRINTER_INFO_2 {aka _PRINTER_INFO_2A*}' (maybe you meant to use '->' ?)

PPRINTER_INFO_2* printerInfo = NULL;

void ChangedPrinter()
{
...
DWORD attributesPrinterInfo;

printerInfo = (PPRINTER_INFO_2*) malloc(bufferSize);

attributesPrinterInfo = printerInfo->Attributes; // error

free(printerInfo);
}

我做错了什么???

最佳答案

PRINTER_INFO_2结构定义为:

typedef struct _PRINTER_INFO_2 {
// ...
} PRINTER_INFO_2, *PPRINTER_INFO_2;

所以 PPRINTER_INFO_2 是指向 PRINTER_INFO_2 的指针。当你做的时候

printerInfo = (PPRINTER_INFO_2*) malloc(bufferSize);

printerInfo 实际上变成了指向 PRINTER_INFO_2 的指针。我不确定这是故意的还是只是一个错误,但如果它是 PPRINTER_INFO_2* 那么正确的用法是:

(*printerInfo)->Attributes

关于c++ - 错误 : request for member (maybe you meant to use '->' ? ) 已经使用 '->',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14965170/

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