【发布时间】:2012-03-18 14:00:11
【问题描述】:
我的私有构造函数有如下问题:
车道.hpp:
namespace sim_mob
{
class B
{
friend class A;
private:
B(int){}
};
}
xmll.hpp:
#include"Lane.hpp"
namespace geo
{
class A
{
public:
A()
{
sim_mob::B b(2);
}
};
}
main.cpp:
#include"xmll.hpp"
int main()
{
geo::A a;
return 0;
}
命令: $ g++ main.cpp
In file included from main.cpp:2:0:
Lane.hpp: In constructor ‘geo::A::A()’:
Lane.hpp:10:5: error: ‘sim_mob::B::B(int)’ is private
xmll.hpp:9:23: error: within this context
关键是如果我在构造函数中没有任何参数,我就不会收到这个错误。我可以知道为什么我会得到这个以及如何解决它吗? 非常感谢
【问题讨论】:
标签: c++ constructor private friend