I want to use the Object Pool design pattern for my library, so that the user cannot create more than a predefined number of objects.
How can I force the user to use the Pool class for acquiring an instance, instead of constructor of the resource?
I can't declare the resource constructor private because then the pool class won't be able to create the instance either...
Thanks
use composition and a class which holds the collection. IOW, you give them a wrapper type around the collection which adjusts the visibility and handles object creation.
If you really want to restrict resource creation even further, you can bind without friendship using this approach (having seen the c++/friend comments):