I would like to define a staitc member funtion to build my class. This staitc function would access private member, and I make it as friend.
Here is the demo code:
#include <memory>
template<typename T>
class Foo
{
public:
static std::unique_ptr<Foo> Create();
friend static std::unique_ptr<Foo> Foo::Create();
};
template<typename T>
std::unique_ptr<Foo<T>> Foo<T>::Create()
{
return std::unique_ptr<Foo<T>>();
}
template class Foo<int>;
template class Foo<double>;
int main()
{
return 0;
}
It compiles faild. How to fix it?
Aucun commentaire:
Enregistrer un commentaire