C++ and Windows are fighting with each other, and I need to get them to stop.
I have a Visual Studio 2022 generated class that implements CDialogEx, and I need to add this to an array capable of insert. This is hard.
The class that Visual Studio 2022 generated for the dialog looks like this:
class SignPage : public CDialogEx
{
DECLARE_DYNAMIC(SignPage)
public:
SignPage(CWnd* pParent = nullptr); // standard constructor
virtual ~SignPage();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_SIGN_PAGE };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
I understand that the array capable of insert is std::vector, however inserting any Windows generated objects into std::vector results in “attempting to reference a deleted function” errors as Windows has deleted the copy and move functions in their objects.
I do not want the array capable of insert to molest the Windows provided objects in any way, and so I understand std:unique_ptr is what I need so that I add a pointer to the Windows provided objects to the list.
I instantiate the object and vector like this, and the compiler likes it:
std::vector<std::unique_ptr<SignPage>> m_dlgs;
std::unique_ptr<SignPage> upm_dlg1 = std::make_unique<SignPage>();
Now I try and insert the upm_dlg1 into m_dlgs like this:
std::vector<std::unique_ptr<SignPage>>::iterator it;
it = m_dlgs.begin();
m_dlgs.insert(it, upm_dlg1); <---- error happens here
The addition of the last line above causes a compile error inside the template rendering unique pointers as follows:
1>C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807includexmemory(700,82): error C2280: 'std::unique_ptr<SignPage,std::default_delete<SignPage>>::unique_ptr(const std::unique_ptr<SignPage,std::default_delete<SignPage>> &)': attempting to reference a deleted function
Does anyone know what steps I must take to fix this?
My limitations are:
-
The objects I need to add to the array capable of insert are generated by Visual Studio for the benefit of Windows. My options to modify these objects are limited.
-
The compiler error is being triggered deep inside what I understand to be the template implementing unique_ptr. I am assuming this is the joy of c++ compiler errors.
-
I am led to believe that std::vector is the collection I should be using, but this may not be the case, can anyone confirm? I have no need for sorting or any other complexity, just a simple array where I can insert and remove without in any way touching the object in the list.