I'm trying to add a lazy-initialization function to my class. I'm not very proficient with C++. Can someone please tell me how I achieve it.
My class has a private member defined as:
std::unique_ptr<Animal> animal;
Here's the original constructor that takes one parameter:
MyClass::MyClass(string file) :
animal(new Animal(file))
{}
I just added a parameter-less constructor and an Init() function. Here's the Init function I just added:
void MyClass::Init(string file)
{
this->animal = ???;
}
What do I need to write there to make it equivalent to what constructor is doing?
question from:
https://stackoverflow.com/questions/32624077/how-to-initialize-a-unique-ptr 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…