I'm trying to add a lazy-initialization function to my class.
(我正在尝试向类添加延迟初始化函数。)
I'm not very proficient with C++. (我不太精通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.
(我刚刚添加了一个无参数的构造函数和一个Init()函数。)
Here's the Init function I just added: (这是我刚刚添加的Init函数:)
void MyClass::Init(string file)
{
this->animal = ???;
}
What do I need to write there to make it equivalent to what constructor is doing?
(我需要在那里写什么才能使其等同于构造函数在做什么?)
ask by dotNET translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…