cuốn sách gpt4 ai đã làm

c - Lỗi: hàm khai báo là hàm trả về hàm

In lại Tác giả: Taklimakan 更新时间:2023-11-02 23:54:53 30 4
mua khóa gpt4 Nike

我正在将 Windows 程序集移植到 Linux。我有一些代码要移植。我实际上是 linux 中 C 的新手。我知道 C 基础知识是一样的!

typedef struct sReader
{
pReaderAddRef addRef;
pReaderDelRef delRef;
}pReader, *pSReader;

typedef long (*pReaderAddRef)(struct sReader *);
typedef long (*pReaderDelRef)(struct sReader **);

上面的代码给出了错误'pReaderAddRef' declared as function returning a function.

我了解回调函数的工作方式。但我真的不知道如何解决这个错误。

请帮忙。

câu trả lời hay nhất

虽然我不明白你原来的错误信息 - 我明白了

f.c:3:5: error: unknown type name ‘pReaderAddRef’
f.c:4:5: error: unknown type name ‘pReaderDelRef’

使用您的原始代码 -

看来您弄错了顺序:为了使用函数指针,您必须定义它们。

struct sReader; // incomplete type, but ready to be used

//alternatively:
typedef struct sReader pReader, *pSReader; // taken from your edit, but these prefixes are misleading

typedef long (*pReaderAddRef)(struct sReader *); // or mytypename
typedef long (*pReaderDelRef)(struct sReader **);

struct sReader
{
pReaderAddRef addRef; // Now you can use them
pReaderDelRef delRef;
}

关于c - 错误 : function declared as function returning function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21475870/

30 4 0
Taklimakan
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress