gpt4 book ai didi

c++ - 在 C++ 中前向声明 typedef 结构

转载 作者:行者123 更新时间:2023-12-05 01:22:37 24 4
gpt4 key购买 nike

<分区>

我正在使用在 Foo.h 中定义结构的遗留库:

typedef struct { int i; int j; } Foo

但是在我的 C++ 程序中,我试图在头文件中编写以下内容。

// forward-declare the struct
struct Foo;

class Bar {
void myFunction(std::shared_ptr<Foo> foo);
};

在我的 cpp 文件中:

#include "Foo.h"

然而,这失败并出现错误:

typedef redefinition with different types ('struct Foo' vs 'Foo')

执行此操作的正确语法是什么?

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