C++ 将指向正向声明类型的指针推入typedef';时出现编译器错误;d向量

C++ 将指向正向声明类型的指针推入typedef';时出现编译器错误;d向量,c++,pointers,vector,reference,C++,Pointers,Vector,Reference,所以我得到的错误是: error: no matching function for call to 'std::vector<Type*>::push_back(AnimationAutoComplete::Type*&)' neighbours.push_back(samplePoint); ^ 和mymain.cpp #include "AnimationAutoComplete.h" SetOfC

所以我得到的错误是:

error: no matching function for call to 'std::vector<Type*>::push_back(AnimationAutoComplete::Type*&)'
 neighbours.push_back(samplePoint);
                                 ^
和my
main.cpp

#include "AnimationAutoComplete.h"

SetOfConstTQ AnimationAutoComplete::getNeighbours()
{
    SetOfConstTQ neighbours;

    Type *samplePoint = new Type();

    neighbours.push_back(samplePoint);

    return neighbours;
}

int main()
{
    AnimationAutoComplete main;
}

动画自动完成
之外定义
类型
,您将修复程序:

#include <vector>

class Type;
typedef std::vector<Type *> SetOfConstTQ;

class AnimationAutoComplete { ... };

class Type { ... };
...
谢谢你

动画自动完成
之外定义
类型
,您将修复程序:

#include <vector>

class Type;
typedef std::vector<Type *> SetOfConstTQ;

class AnimationAutoComplete { ... };

class Type { ... };
...

您不能以这种方式转发声明。
AnimationAutoComplete::Type
Type

不同,您不能以这种方式向前声明。
动画自动完成::Type
Type

不同如上所述,不能向前声明嵌套类

但如果您希望嵌套类,则可以在类中键入def并在以后使用,如:

class AnimationAutoComplete {
public:
  AnimationAutoComplete() {}
  ~AnimationAutoComplete() {}

  class Type
  {
  public:
      Type() {}
      const double point = 3.0;
  };

  typedef std::vector<Type *> SetOfConstTQ; // Typedef here
  SetOfConstTQ getNeighbours(); // use it after typedef
};

AnimationAutoComplete::SetOfConstTQ AnimationAutoComplete::getNeighbours() // return type will come under scope of AnimationAutoComplete
{
    SetOfConstTQ neighbours;

    Type *samplePoint = new Type();

    neighbours.push_back(samplePoint);

    return neighbours;
}
类动画自动完成{
公众:
AnimationAutoComplete(){}
~AnimationAutoComplete(){}
类类型
{
公众:
类型(){}
常数双点=3.0;
};
typedef std::vector setOfconstq;//此处为typedef
setOfConstq getNeights();//在typedef之后使用它
};
AnimationAutoComplete::SetOfConstq AnimationAutoComplete::GetNeights()//返回类型将属于AnimationAutoComplete的范围
{
CONSTTQ邻居集;
类型*采样点=新类型();
邻居。推回(采样点);
返回邻居;
}

如上所述,不能向前声明嵌套类

但如果您希望嵌套类,则可以在类中键入def并在以后使用,如:

class AnimationAutoComplete {
public:
  AnimationAutoComplete() {}
  ~AnimationAutoComplete() {}

  class Type
  {
  public:
      Type() {}
      const double point = 3.0;
  };

  typedef std::vector<Type *> SetOfConstTQ; // Typedef here
  SetOfConstTQ getNeighbours(); // use it after typedef
};

AnimationAutoComplete::SetOfConstTQ AnimationAutoComplete::getNeighbours() // return type will come under scope of AnimationAutoComplete
{
    SetOfConstTQ neighbours;

    Type *samplePoint = new Type();

    neighbours.push_back(samplePoint);

    return neighbours;
}
类动画自动完成{
公众:
AnimationAutoComplete(){}
~AnimationAutoComplete(){}
类类型
{
公众:
类型(){}
常数双点=3.0;
};
typedef std::vector setOfconstq;//此处为typedef
setOfConstq getNeights();//在typedef之后使用它
};
AnimationAutoComplete::SetOfconStatq AnimationAutoComplete::GetNeurs()//返回类型将在AnimationAutoComplete的范围内
{
CONSTTQ邻居集;
类型*采样点=新类型();
邻居。推回(采样点);
返回邻居;
}

::Type
不是
::Whatever::Type
::Type
不是
::Whatever::Type
。您应该提到,将声明移动到外部类中也是一个有效的解决方案。@MaximilianKöstler我刚才就是这么做的;)您应该提到,将声明移动到外部类中也是一个有效的解决方案。@MaximilianKöstler我刚才就是这么做的;)