[英]Why am I getting undefined type error after a forward-declaration?
I'm using this code in C++ CLI. 我在C ++ CLI中使用此代码。 However this shouldn't make any difference from C++.
但是,这与C ++应该没有什么区别。
I'm looking for a solution to get rid of that error. 我正在寻找解决方案来摆脱这个错误。
Code : 代码:
ref class B;
ref class A;
public ref class A
{
public:
A() {}
B^ b;
void HelloFromA(){
b->HelloFromB();
}
};
public ref class B
{
public :
A^ a;
B() {}
void HelloFromB(){
a->HelloFromA();
}
};
You need to move the bodies of the functions that invoke member functions on the forward-declared classes outside of the headers, to places where definitions are available: 您需要将在标头之外的,在向前声明的类上调用成员函数的函数的主体移到可以使用定义的地方:
void A::HelloFromA(){
b->HelloFromB();
}
Otherwise, the compiler knows that B
is available, but it does not know that B
has the HelloFromB
member function that takes no arguments. 否则,编译器知道
B
可用,但它不知道B
具有不带参数的HelloFromB
成员函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.