Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Error C2280 with MSC15 and Uniq (Error C2280 with MSC15 and Uniq (attempting to reference a deleted function))
Error C2280 with MSC15 and Uniq [message #47033] Wed, 16 November 2016 03:39 Go to next message
awksed is currently offline  awksed
Messages: 61
Registered: April 2012
Member
I'm getting error C2280 (attempting to reference a deleted function) with MSC15 (pick() usually fixes most of these)
but there is a line in Uniq that is causing problems: PostCallback(callback1(WhenInstance, v));.

MSC15x64 compiler -Od switch

(no problem with MSC10x64)

Snippets:

class Uniq
{
// callback called when another app instance is run
//
Callback1<Vector<String> const &> WhenInstance;
}

bool Uniq::SendCmdLine(void)
{
// ok, we're (finally...) connected to client
// just get command line from him

Vector<String> v;

int count = ScanInt(ReadFileString(pipe));

for(int i = 0; i < count; i++)
v.Add(ReadFileString(pipe));

// This causes the following error:
// C:\upp\bazaar\Uniq\Windows.cpp(109): error C2280: 'Upp::Vector<Upp::String>::Vector(const Upp::Vector<Upp::String> &)': attempting to reference a deleted function
//
PostCallback(callback1(WhenInstance, v));


Is there a compiler switch to stop generated functions from being deleted or what changes need to be made the the code?

Thanks,

Jan
Re: Error C2280 with MSC15 and Uniq [message #47034 is a reply to message #47033] Wed, 16 November 2016 14:10 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Hi,

a possible solution is tu use lambda instead of callback1 :

PostCallback([&](){WhenInstance(v);});


regards
omari.
Re: Error C2280 with MSC15 and Uniq [message #47035 is a reply to message #47034] Wed, 16 November 2016 15:50 Go to previous messageGo to next message
awksed is currently offline  awksed
Messages: 61
Registered: April 2012
Member
Hi omari,

Thank you for your reply.

Unfortunately PostCallback([&](){WhenInstance(v);}); results in:

error C2664: 'void Upp::PostCallback(Upp::Callback,void *)': cannot convert argument 1 from 'Upp::Uniq::SendCmdLine::<lambda_dc6ff328973047984323327a9646bad3 >' to 'Upp::Callback'
note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Any ideas how to fix error C2664 (some cast perhaps)?

Thanks,

Jan
Re: Error C2280 with MSC15 and Uniq [message #47036 is a reply to message #47033] Wed, 16 November 2016 23:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
awksed wrote on Wed, 16 November 2016 03:39
I'm getting error C2280 (attempting to reference a deleted function) with MSC15 (pick() usually fixes most of these)
but there is a line in Uniq that is causing problems: PostCallback(callback1(WhenInstance, v));.

MSC15x64 compiler -Od switch

(no problem with MSC10x64)

Snippets:

class Uniq
{
// callback called when another app instance is run
//
Callback1<Vector<String> const &> WhenInstance;
}


PostCallback(callback1(WhenInstance, v));


Trouble is using callback1 here... You are trying to 'deep copy' v (because it needs to become the part of callback value), but v does not have copy... (it is 'deleted').

To pass v into callback1, you need to use 'clone' or 'pick'. Which is a bit of trouble without C++14, but in C++14 you can use lambda with explicit copy specification like:


CONSOLE_APP_MAIN
{
	Event<const Vector<int>&> h = [](const Vector<int>& x) { DUMP(x); };

	Event<> ev;

	{
		Vector<int> x = { 1, 2 };
		ev = [=, x = pick(x)] { h(x); };
	}
	
	ev();
}



(this is in current trunk, upcoming 2016 release, but should work with Callback instead of Event too).

Alternatively, using

WithDeepCopy< Vector<String> > v;


would work too, with possible perfomance hit (if v is to be big)

[Updated on: Wed, 16 November 2016 23:25]

Report message to a moderator

Re: Error C2280 with MSC15 and Uniq [message #47037 is a reply to message #47036] Thu, 17 November 2016 11:44 Go to previous message
awksed is currently offline  awksed
Messages: 61
Registered: April 2012
Member
Hi mirek,

WithDeepCopy< Vector<String> > v; allows bazaar/Uniq/Windows.cpp to compile.

Many thanks,

Jan
Previous Topic: lambda troubles...
Next Topic: Are there any plans to convert U++ comments to format as DOXYGEN / JAVADOC?
Goto Forum:
  


Current Time: Thu Mar 28 17:50:59 CET 2024

Total time taken to generate the page: 0.01144 seconds