[flyweights] private constructor, friend access
Dear all, On a project of mine, I started to use Boost.Flyweight. I would like users of my class to only be able to instantiate objects of my class by using the Boost.Flyweight mechanism. For this, I make my class constructor private. However, when doing so the corresponding flyweight factory also cannot instantiate my class. What classes do I need to `friend` in order to make this work? Here's a small self-contained example of the problem: class X { public: int data() const { return m_data; } struct key_extractor { int operator()(const X& x) const { return x.data(); } } typedef boost::flyweights::flyweight < boost::flyweights::keyvalue < int, X, key_extractor > > flyweight; private: int m_data; X(int x) : m_data(x) {} // friend declarations should go here }; int main() { auto my_x = X::flyweight(42); return 0; } Kind regards, Raoul Wols
Dear all,
On a project of mine, I started to use Boost.Flyweight. I would like users of my class to only be able to instantiate objects of my class by using the Boost.Flyweight mechanism. For this, I make my class constructor private. However, when doing so the corresponding flyweight factory also cannot instantiate my class. What classes do I need to `friend` in order to make this work?
You need to do
template
participants (2)
-
Joaquin M Lopez Munoz
-
r@primef.actor