I have not used std::make_unique before, and code inspection encouraged me to do it.
If I use this, it does not display errors:
auto x = make_unique<CChristianLifeMinistryHtmlView>();
But when I try it with my class member variable CChristianLifeMinistryHtmlView *m_pHtmlPreview it does not like it:
m_pHtmlPreview = std::make_unique<CChristianLifeMinistryHtmlView>();
How do I use std::make_unique with a member variable of the class?
Your issue is nothing to do with the class member, rather its type!
std::make_unique()returnsstd::unique_ptrfor the template typeT(i.e.std::unique_ptrof an instance of typeT)The member
is a pointer to a
CChristianLifeMinistryHtmlView, not astd::unique_ptr. Hence, the type mismatch.Therefore, you need to use
std::unique_ptr<CChristianLifeMinistryHtmlView>as the type of them_pHtmlPreviewmember:If it is a long typing, a type alias wouldn't be a bad idea: