下面的代码给我:
In member function ‘void A::method()’:error: incomplete type ‘B’ used in nested name specifier B::meth();
我在 SO 上搜索了此错误的解决方案,发现我可以使用 ::
但没有帮助
class B;
class A
{
public:
void method()
{
B::meth();
}
};
class B
{
public:
void static meth()
{
}
};
最佳答案
在定义 A::method
行,B
仅通过名称而不是其完整定义而为人所知。
在使用 B::meth()
之前,您必须确保知道 B
的完整定义。
选项 1
将 B
的定义移到 A
的定义之前。
class B
{
public:
void static meth()
{
}
};
class A
{
public:
void method()
{
B::meth();
}
};
选项 2
将 A::method
的定义移到 B
的定义之后。
class A
{
public:
void method();
};
class B
{
public:
void static meth()
{
}
};
void A::method()
{
B::meth();
}
关于c++ - 嵌套命名空间中使用的不完整类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36256111/