Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
jonndoe47
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Apr 06, 2020 7:45 pm

Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by jonndoe47 » Mon Apr 06, 2020 7:56 pm

I'm using Visual Studio Community 2019, I'm new to VS/C++ & WX Widgets but have been a programmer for 30 odd years.

Installed wxwidgets with vcpkg.

So , I'm using the tutorial hello world example, cut and paste. Not working, looked around the web then found out I have to add:

Code: Select all

#define __WXMSW__
#define WXUSINGDLL
before the #include. Try again. Get the error at the top (subject). So, this don't work. Hmm. Then I add:

Code: Select all

int main(int argc, char** argv)
{
    MyApp app;
    app.OnInit();
}
I get a thrown exception:

Code: Select all

Exception thrown: read access violation.
**this** was nullptr. occurred

    _NODISCARD iterator begin() noexcept {
        return iterator(_Mypair._Myval2._Myhead->_Next, _STD addressof(_Mypair._Myval2));  **** exception here in std::list
    }
Hmm, so obviosuly I did wrong with the init and call of the MyApp.... What is the proper way to init and call the MyApp object ? I'm a newbie so go easy please!!!!
Last edited by catalin on Mon Apr 06, 2020 8:03 pm, edited 1 time in total.
Reason: code tags

User avatar
doublemax
Moderator
Moderator
Posts: 14769
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by doublemax » Mon Apr 06, 2020 8:08 pm

Please start by building and running the "minimal" sample that comes with wxWidgets, using the provided VS solution files.
(in <wxdir>/samples/minimal/)
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2355
Joined: Sun Jan 03, 2010 5:45 pm

Re: Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by PB » Mon Apr 06, 2020 8:09 pm

Your code is very wrong. Please check the Hello World example to see how you are supposed to initialize wxWidgets and create your wxApp instance:
https://docs.wxwidgets.org/trunk/overvi ... world.html

Please also check the MSW install guide (those two defines should not be in the header/source file but be set in the project settings, in preprocessor defines BTW), particularly the MSVC section:
https://docs.wxwidgets.org/trunk/plat_msw_install.html

jonndoe47
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Apr 06, 2020 7:45 pm

Re: Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by jonndoe47 » Mon Apr 06, 2020 8:26 pm

I still had to leave the two lines I added at the top:

#define __WXMSW__
#define WXUSINGDLL

I am now getting:

Code: Select all


Severity	Code	Description	Project	File	Line	Suppression State
Error	C2598	linkage specification must be at global scope	t2	C:\VS Projects\t2\main.cpp	72	

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2601	'WinMain': local function definitions are illegal	t2	C:\VS Projects\t2\main.cpp	72	

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2601	'wxGetApp': local function definitions are illegal	t2	C:\VS Projects\t2\main.cpp	72	

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2601	'wxCreateApp': local function definitions are illegal	t2	C:\VS Projects\t2\main.cpp	72	


I'm an idiot.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2355
Joined: Sun Jan 03, 2010 5:45 pm

Re: Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by PB » Mon Apr 06, 2020 8:40 pm

jonndoe47 wrote:
Mon Apr 06, 2020 8:26 pm
So again I ask, how do init and run an MyApp object instance if not through main?
Sorry to be blunt, but you were already told that:
1. Your code is utterly wrong: a wxWidgets GUI app generally does not define main() and the wxApp instance is not created on the stack.
2. You should not use those preprocessor defines in a header/source file, these must be defined (if needed; WXUSINGDLL only if using a dynamic build of wxWidgets) for a whole project. I do not use vcpgk but I would expect it to set all the project defines for you?
3. How to actually init and run the wxApp is is all properly explained in the Hello World tutorial I linked above.

Is there anything you did not understand?

jonndoe47
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Apr 06, 2020 7:45 pm

Re: Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by jonndoe47 » Tue Apr 07, 2020 10:12 am

The problem was this:

Check your property sheets under Linker->System->SubSystem. Make sure the subsystem is Windows and not Console.

Found answer on stackoverflow. Thanks for the bluntness, I did say I changed the code but you chose to have a go at me instead. Nice way to treat new users.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2355
Joined: Sun Jan 03, 2010 5:45 pm

Re: Error C2280 'MyApp::MyApp(const MyApp &)': attempting to reference a deleted function

Post by PB » Tue Apr 07, 2020 10:48 am

jonndoe47 wrote:
Tue Apr 07, 2020 10:12 am
I did say I changed the code but you chose to have a go at me instead.
I cannot find any mention of you changing the invalid code anywhere in this thread. I also apologize for not being clever enough to deduce you for some reason decided to chose to use a console subsystem when wanting a GUI application. I did not bother to carefully inspect all the error messages since I knew the code was invalid and hence the error messages irrelevant.

I answered all your questions and pointed out the mistakes you did in a hope it will help you. Yet, you just kept repeating the already answered questions (e.g, how to implement main()). It is very difficult to help someone who does not want to be helped...

Post Reply