问题描述
class B;
namespace test{
class A
{
public:
A(B* b);
private:
B* bb_;
};
}
#include "a.hh"
#include "b.hh"
namespace test{
A::A(B* b)
: bb_(b)
{
}
}
namespace test{
class B
{
int some;
};
}
报错原因是 cannot initialize a member subobject type B * with an lvalue of type test::B *
原因在于前向声明没有放到namespace test中去。
我们会默认为存在俩个类,一个是::B
一个是test::B
我们手动加上命名空间实际上是
#include "a.hh"
#include "b.hh"
namespace test{
A::A(test::B* b)
: (::B)bb_(b)
{
}
}
修改
就是在a.hh中,将前向声明B放到namespace test中去。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)