I currently have something like this. I would like to only allow the bar
class to create an instance of the foo
class so I have made it a friend of foo
and made the constructor of foo
private.
foo.h
class foo
{
friend class bar;
private:
foo()
{
}
}
bar.h
#include "foo.h"
class bar
{
private:
boost::shared_ptr<foo> f;
public:
bar()
{
f = boost::shared_ptr<foo>(new foo());
}
}
The above works perfectly fine. However since the private member of the foo class is only being used in the constructor of the bar class (for instantiating). I would like to restrict private accessibility to only the constructor of the bar class so I decided to replace
friend class bar;
with this
friend bar::bar();
This does not work as the error messages says that bar is an incomplete type (Which I believe means that it cant find bar). Any suggestions on how to fix this problem ?