gpt4 book ai didi

c++ - 转发声明指向类的指针以在类声明中使用的正确方法是什么?

转载 作者:行者123 更新时间:2023-11-30 02:07:36 25 4
gpt4 key购买 nike

例如,

   class Segment
{
friend bool someFunc( P_Segment p );
};

typedef boost::shared_ptr<Segment> P_Segment;

如何最好地声明 P_Segment 以便编译?

最佳答案

在这种情况下,您别无选择,因为您不能转发声明 typedef。您必须改为转发声明 Segment 类。

class Segment;

typedef boost::shared_ptr<Segment> P_Segment;

class Segment
{
friend bool someFunc( P_Segment p );
};

关于c++ - 转发声明指向类的指针以在类声明中使用的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7649749/

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