Possible Duplicate:
How to allow template function to have friend(-like) access?
How do I give function template Load
friend access to class Foo
?
The objective here is to restrict access to the constructor: only function template Load
may construct.
CODE (please ignore memory leak)
class Foo {
Foo() { }
template<> friend Foo const& Load<Foo>(); // error here
};
template<typename T>
T const&
Load() { return *(new T); }
int main( int argc, char* argv[] )
{
Foo const& f = Load<Foo>();
}