0

i want to use unique_ptr for a QMenu without making it as a child of the base widget so i have declared it like this

private:
std::unique_ptr<QMenu> m_pMenu;

and in constructor

std::unique_ptr<QMenu> m_pMenu ( new QMenu());
m_pMenu->setObjectName("JobContextMenu");

i also added CONFIG += c++11 in my .pro file but when compiling the unique_ptr is returning an error as Invalid application of 'sizeof' to an incomplete type 'QMenu'

Wagmare
  • 1,354
  • 1
  • 24
  • 58

1 Answers1

0

Duplicate definition. Also, you can do it in such way in C++ 11:

private:
std::unique_ptr<QMenu> m_pMenu = std::unique_ptr<QMenu>(new QMenu);
UndeadDragon
  • 717
  • 8
  • 23
  • What do you mean by "duplicate defintion"? – cmannett85 Jun 09 '15 at 08:24
  • you shouldn't mix `new` and `unique_ptr`. Use `std::make_unique` to construct the menu. – Nicolas Holthaus Jun 09 '15 at 10:51
  • make_unique is C++ 14 feature, not C++ 11. – UndeadDragon Jun 09 '15 at 10:58
  • sure, it's c++14 (which the OP makes no mention of not being able to use), but this feature has been supported in all major compilers for some time. I down-voted your answer because it lacks substance and the advice is already dated, and will only become more so as time goes on and people look at this answer in the future. – Nicolas Holthaus Jun 10 '15 at 15:02
  • @NicolasHolthaus, maybe in your usa everyone uses newest compilers, but in Russia and most of countries (as far as I know) there are very large limits on many works with compiler versions. So it is very desirable to take into account this fact. topic starter set his config to C++ 11 and I give advice for C++ 11. – UndeadDragon Jun 11 '15 at 07:47