#include <iostream>

// A factory class that will not call anything except constructor. Even if it could.
template<typename T> class HonestFactory
{
	// A factory class that would like to mess with private methods. But it can't.
	friend class HeinousFactory;
	
	// This will ensure only Heinous one can use it.
	HonestFactory() { }
	
	// Real one should be a variadic template.
	T Create()
	{
		return T{};
	}
};

class Foo
{
	friend class HonestFactory<Foo>; // We trust the honest one.
	Foo() { }
	int m_foo {0};
	
public:
	int m_bar {1};
};

class HeinousFactory
{
public:
	Foo CreateFoo()
	{
		HonestFactory<Foo> factory;
		Foo foo = factory.Create();
		//foo.m_foo = 1; // Error.
		foo.m_bar = 1;
		return foo;
	}
};

int main()
{
	//Foo foo1; // No.
	//HonestFactory<Foo> factory; // Nope.
	HeinousFactory factory;
	Foo foo2 = factory.CreateFoo();
	std::cout << foo2.m_bar << std::endl;
}