共享指针类型前缺少分号

missing semi-colon before shared pointer type

本文关键字:指针 类型 共享      更新时间:2023-10-16

我不顾一切地与这个琐碎但令人心痛的问题作斗争我有一个类

///A.h
class A
{
   //declare something
};
///A.cpp
//implement that something of A

然后是另一类

///B.h
class A;
class B
{
private:
   A_PTR aptr; //Missing ';' before aptr
public:
   A_PTR getA();
};
///B.cpp
typedef std::shared_ptr<A> A_PTR;
//implement all B's methods

为什么我在A_PTR上收到一条错误消息,声明B类中的aptr?

因为尚未定义A_PTR。你需要将定义移动到你使用它的第一个点之上:

///B.h
class A;
typedef std::shared_ptr<A> A_PTR;
class B
{
private:
   A_PTR aptr;
public:
   A_PTR getA();
};
相关文章: