C++ 是否有任何方法可以在不引用其模板类型的情况下向前声明指向类的指针?

C++ 是否有任何方法可以在不引用其模板类型的情况下向前声明指向类的指针?,c++,pointers,forward-declaration,C++,Pointers,Forward Declaration,在foo.h中: #include <vector> class A { int x; }; typedef std::vector<A> AVector; #包括 甲级{ int x; }; typedef std::向量向量向量向量; 我想把这个放在酒吧里。h: #include <vector> <<< some forward declaration of AVector here>>>; class

在foo.h中:

#include <vector>
class A {
    int x;
};
typedef std::vector<A> AVector;
#包括
甲级{
int x;
};
typedef std::向量向量向量向量;
我想把这个放在酒吧里。h:

#include <vector>
<<< some forward declaration of AVector here>>>;

class B {
    AVector *myVector;
};
#包括
>;
B类{
AVector*myVector;
};
我想将声明“AVector”转发到bar.h中,而不包含bar.h必须包含类A的定义。因为类B只需要知道它是一个指针,而不需要知道指针内的细节,所以我希望有某种方法来声明它


注意:我知道我可以直接声明“void*”,然后在不同的点上施法。我宁愿不失去类型安全。任何失去类型安全性的解决方案都不能解决我的问题

从Jean BaptisteYunè对这个问题的评论中,您可以向前声明一个std::vector,而不需要a的完整定义。这意味着这是可行的:

class A;
typedef std::vector<A> AVector;
class B {
    AVector *myVector;
};
A类;
typedef std::向量向量向量向量;
B类{
AVector*myVector;
};

在C++17之前,当
A
不是完整类型时,不允许说
std::vector
。@KerrekSB我认为只要你不实例化
std::vector
(并且声明指向
std::vector
的指针不会实例化它),你就可以说
,然后你需要以某种方式给出类型<代码>A类;typedef std::向量向量向量向量很好用。@Jean BaptisteYunès我将把你的回答交给你。这显然有效。我认为必须有完整的类型A才能向前声明std::vector。显然不是!