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 » U++ Library support » U++ Core » Please help! New transfer semantic issue!
Please help! New transfer semantic issue! [message #46161] Mon, 21 March 2016 12:36 Go to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Maybe problem is trivial, but I stopped on it.

There is class Line
class Line {
    ....
        Line( Point p1, Point p2 ) // constructor
}


and class Figure
class Line {
   public:
       Array<Line> lines;
}


and if I use compiler option -std=c++11

I get error message while adding new Line to Lines
lines.Add(Line(p1,p2));


Without option -std=c++11 all OK.

What right way to do this with -std=c++11 option?


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Please help! New transfer semantic issue! [message #46163 is a reply to message #46161] Mon, 21 March 2016 13:52 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

sergeynikitin wrote on Mon, 21 March 2016 12:36
if I use compiler option -std=c++11

I get error message while adding new Line to Lines
lines.Add(Line(p1,p2));


Hi Sergey,

What does the error message say? It is really hard to guess without seeing the entire class nor the error...

Best regards,
Honza
Re: Please help! New transfer semantic issue! [message #46164 is a reply to message #46161] Mon, 21 March 2016 13:55 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
AFAIK, in case of C++11 you should explicitly call pick() here.
Mirek is working on refactoring of Upp, so this requirement will be gone soon.


Regards,
Novo
Re: Please help! New transfer semantic issue! [message #46165 is a reply to message #46163] Mon, 21 March 2016 14:02 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Error message is
required from 'T& Upp::Array<T>::Add(const T&) [with T = Line]'
error: use of deleted function 'Line::Line(const Line&)'


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Mon, 21 March 2016 14:05]

Report message to a moderator

Re: Please help! New transfer semantic issue! [message #46166 is a reply to message #46165] Mon, 21 March 2016 14:07 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Code of adding
void AddLine(Point p1, Point p2){
	lines.Add(Line(p1,p2));
	moving_line = lines.GetCount()-1;
}


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Please help! New transfer semantic issue! [message #46168 is a reply to message #46166] Mon, 21 March 2016 14:47 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
sergeynikitin wrote on Mon, 21 March 2016 14:07
Code of adding
void AddLine(Point p1, Point p2){
	lines.Add(Line(p1,p2));
	moving_line = lines.GetCount()-1;
}


Hi Sergey,

I guess the error disappear if you use

void AddLine(Point& p1, Point& p2)

Luigi
Re: Please help! New transfer semantic issue! [message #46169 is a reply to message #46168] Mon, 21 March 2016 16:22 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Thanks for opinion.
But Next function has no parameters:
void AddMovingLine(){
	lines.Add(Line(checked_elem_point+Point(0,0),checked_elem_point+Point(0,0)));
	moving_line = lines.GetCount()-1;
}


But have same problem.

There are problems while creating array item.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Please help! New transfer semantic issue! [message #46171 is a reply to message #46169] Mon, 21 March 2016 22:48 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Quote:

Error message is
 
required from 'T& Upp::Array<T>::Add(const T&) [with T = Line]'
error: use of deleted function 'Line::Line(const Line&)'



it appears that you have explicitly deleted copy ctor for Line class.

change the line to
     lines.AddPick(Line(p1,p2));

should fix your problem.
Re: Please help! New transfer semantic issue! [message #46172 is a reply to message #46161] Tue, 22 March 2016 06:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
This depends on Line definition. Could you post complete Line?

Mirek
Re: Please help! New transfer semantic issue! [message #46173 is a reply to message #46172] Tue, 22 March 2016 07:18 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Yes.

class Line {
		typedef Line CLASSNAME;
	public:
		void Paint ( Draw& w, bool moving );
		Line();
		Line( Point _p1, Point _p2 );
		String ToString() const;
	public:
		Point p1, p2;
		ElementPin* elp1;
		ElementPin* elp2;
		Array<Segment> segs;
		Array<ElementPin> lines;
};



SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Please help! New transfer semantic issue! [message #46174 is a reply to message #46173] Tue, 22 March 2016 21:47 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Contained members Array<Segment> segs and Array<ElementPin> lines are the culprits.

Mirek would be able to give you the best suggestion. However explicitly define a copy constructor and a move constructor will fix the problem.

Something like
// public:

    Line(const Line& ln):p1(ln.p1),p2(ln.p2), elp1(???),elp2(???),
                      segs(ln.segs,1), // make a deep copy 
                      lines(ln.lines,1)  // ditto
                     {}

    Line(Line&& ln): p1(ln.p1),p2(ln.p2),elp1(???), elp2(???),
                     segs(pick(ln.segs)),
                     lines(pick(ln.lines))
                    {}



Re: Please help! New transfer semantic issue! [message #46201 is a reply to message #46174] Fri, 25 March 2016 18:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I you want to maintain pick/clone distinction, you should implement "clone" constructor/operator:

    Line(const Line& ln, int):p1(ln.p1),p2(ln.p2), elp1(???),elp2(???),
                      segs(clone(ln.segs)), // make a deep copy 
                      lines(clone(ln.lines))  // ditto
                     {}
// and operator=....


If you do not care, you can also use WithDeepCopy

...
WithDeepCopy<Array<Segment> > segs;
...


Things might get simpler with C++11...

Mirek
Re: Please help! New transfer semantic issue! [message #46273 is a reply to message #46201] Wed, 06 April 2016 10:48 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Thanks. It's works with or without C++11 option!
Real crossplatforming (even through C++ version Smile )!


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Previous Topic: conversion from String to wchar_t
Next Topic: How to handle a lack of memory
Goto Forum:
  


Current Time: Thu Mar 28 11:21:33 CET 2024

Total time taken to generate the page: 0.01675 seconds