[英]C++ Incomplete class type pointer
In a source file I have 2 class definitions 在源文件中,我有2个类定义
class Foo
{
public:
int * GetPtr(){
return Obj;
}
int * Obj;
}
class Bar
{
public:
...
std::vector<Foo> FooVector;
}
And in the same source file I have this function 在同一个源文件中我有这个功能
void DoSomething()
{
Bar* barVar = CreateBar(); // Returns pointer to class object
Foo* fooVar = &barVar->FooVector[0];
if (fooVar->GetPtr()) // Error here
...
}
Trying to compile this, I get the error "Pointer to incomplete class type not allowed" but the class is defined a few lines above it. 试图编译这个,我得到错误“不允许指向不完整类类型的指针”,但是类被定义在它上面几行。
我通过正确实现类来解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.