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 » Community » Newbie corner » Issues using 2015.2 version
Issues using 2015.2 version [message #45891] Thu, 21 January 2016 11:31 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
I have just a brand new pc with windows 10. I used the 2015.1 ultimate++ version till yesterday. So, new OS, new upp version and new compiler... I am having trouble compiling my old projects and having all this new stuff I do not know where the problem sits. In this specific case, I am trying to compile a test code for a barcode generator library. The library was downloaded here in the forum. I am trying to compile the test application that comes with the library, and get the following error:

Barcode\Code128.cpp(701): error C2280: 'Upp::Vector<Upp::byte> &Upp::Vector<Upp::byte>::operator =(const Upp::Vector<Upp::byte> &)': trying to reference a deleted function


The same application compiles fine on my previous platform: windows 7, upp 2015.1 and MSC 12.

Any suggestion?
Thanks,
Gio
Re: Issues using 2015.2 version [message #45892 is a reply to message #45891] Thu, 21 January 2016 13:17 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Giorgio,

Wild shoot in the dark: Have you used C++11 before the upgrade? If I remember correctly, deleted assignment operator can happen only with C++11, so perhaps the package is not quite C++11 ready.

Best regards,
Honza
Re: Issues using 2015.2 version [message #45893 is a reply to message #45892] Thu, 21 January 2016 13:48 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi Dolik,
actually I do not really know Sad, programming is not my first duty and that package was found in the forum...
Regards,
Gio

[Updated on: Fri, 22 January 2016 14:36]

Report message to a moderator

Re: Issues using 2015.2 version [message #45894 is a reply to message #45893] Thu, 21 January 2016 18:34 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Hi Giorgioļ¼š

Not sure if you are directly using the BarcodeTest program, anyway, the following line generates the problem you referred to

GUI_APP_MAIN
{
	auto a=MyApp();                       <============ This line
	a.Sizeable().MaximizeBox();
	a.Maximize();
	a.Run();

}


while MyApp has this definition
struct MyApp : WithBarcodeTestLayout<TopWindow>
{
	MyApp(){
		CtrlLayout(*this, "Barcode Test");
		input<<=THISBACK(Updated);
		print.SetImage(CtrlImg::print())<<=THISBACK(Print);
		top<<=2;
		left<<=2;
	}
	
	virtual void Paint(Draw& w);
	
	void GenBarcode();
	void Print();
	
	void Updated()
	{
		Refresh();
		Code128 c(String().Cat()<<~input);
		EAN ean(AsString(~input));
		PDF417 pdf(AsString(~input));
		richview.SetQTF(String("[ ").Cat()
			<<c.DisplayText("Hi, U++ user!")
				.Color(Red()).BarRatio(36)
			<<"&&" // new line
			<<ean.Type(EAN::EAN8UPCAEAN13)
				.DisplayText("Best Seller")
			<<"&&"
			<<pdf.FixedAspectRatio(3,2)
		);
	}
	
	typedef MyApp CLASSNAME;
	
};


There are not even any data members (except ones inherits from its ancestors) in the MyApp struct definition, so it could not be because of anything from my barcode library.

I am also puzzled on that line. Logically local variable a should be default constructed once, instead of a default construct of a temporary and then an assignment, so it should be equivalent to
    MyApp a;


Apparently I was wrong. Anyway, change the line to above fixed the problem. I was wondering why should I use the more cumbersome form at first place. So if you are using the BarcodeTest program directly, change the GUI_MAIN to the following form will fix your problem:

GUI_APP_MAIN
{
	MyApp a;
	a.Sizeable().MaximizeBox();
	a.Maximize();
	a.Run();

}



HTH
Re: Issues using 2015.2 version [message #45895 is a reply to message #45894] Thu, 21 January 2016 20:16 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Hi, Giorgio.
Good news is that I know exactly why you have such error.
It's simple: your new compiler is C++11 compiler. And thus U++ is compiled in C++11 mode. It means, among other things, that you must now specify whether you use Pick or Clone operation.
For example, this code is valid for U++ in 'old' mode:
Vector<int> a,b; a = b;

But it fails to compile in U++11 mode because you should use pick/clone and call it explicitly:
Vector<int> a,b; a = pick(b);

Of course, you may use clone() only if your object supports it.
Please refer to the updated Help documentation for details.
Re: Issues using 2015.2 version [message #45899 is a reply to message #45891] Fri, 22 January 2016 15:08 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
first of all I want say a big thank you to everybody. Dorik noticed who the problem was a c++ 11 related issue, Lance who developed the library and find the problem and MindTraveller who solved the puzzle. I really appreciate your support. You guys made the open source great.

That said, and going back to my problem, the problem is solved Smile. The issue was at line 701 of the "code128.cpp" source file in the BarCode package. There is here an assignment not valid for c++ 11. This is how it is:

data=enc.GetEncoded();


Adding pick or clone solves the issues:

data= clone(enc.GetEncoded());


As I said before I am not a really expert c++ developer (my duties are just 15-20% related to programming and less than 5% related to c++ programming), so I do not know if is better using pick or clone. In my case both work. Any suggestion about what is better are welcome. Finally, maybe Lance can update its library (for future users).
Regards,
Giorgio
Re: Issues using 2015.2 version [message #45902 is a reply to message #45891] Sat, 23 January 2016 12:08 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
I think this ideal case for pick(), as you pick up content of return value (leaving it empty), which is discarded anyway right away.

In programming you always should be sort of aware how you use the computer memory.
In C++ you have great control over it, actually just by reading source you can tell quite exactly, how the memory is used.

Vector is built of two parts, the Vector container data like size, capacity and pointer to the data itself; this part is of constant memory size, and is cheap to allocate/copy/destroy, so it's often instantiated on the actual scope stack.
And then there're the data itself, which are allocated on the heap memory, as there may be lot of them, and the pointer to the heap is stored inside the container inner structure.

pick() is sort of "copy constructor", which will copy the size/capacity/pointer from one Vector to the other Vector container, and it will disconnect and invalidate the old container's data pointer. Effectively "moving" the Vector without copying millions of data, only the small constant size Vector container inner structure is copied.

clone() is full copy constructor, which will allocate another (second) block of heap memory for the actual data inside the new Vector instance, and then will copy the actual data from one block of heap memory to the new one.
The old instance of Vector remains fully operational. This is performance expensive operation, and you don't want to do it, unless you actually need a second copy of data.

So when you have a cheap way to move the Vector data around with "pick", you can instantiate Vector inside function, fill it up with data, return the temporary function instantiated Vector (to be released on the very next line after return from function), and pick the data payload to caller's Vector instance, saving them from release, but not copying them one by one.

If you are still confused, which of those two used, use always "pick" in debug mode. In case you mess it up, and access the picked container after, it will crash with some assertion, that you tried to access data from picked Vector, then you can decide if you need a copy, or you accidentally access old Vector instead of the new one.

In case of function returning Vector there's no reason for "clone()", as the source instance is destroyed right away in the function call clean up.
Re: Issues using 2015.2 version [message #45903 is a reply to message #45902] Sat, 23 January 2016 22:59 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
mr_ped wrote on Sat, 23 January 2016 13:08
I think this ideal case for pick(), as you pick up content of return value (leaving it empty), which is discarded anyway right away.

In programming you always should be sort of aware how you use the computer memory.
In C++ you have great control over it, actually just by reading source you can tell quite exactly, how the memory is used.

Vector is built of two parts, the Vector container data like size, capacity and pointer to the data itself; this part is of constant memory size, and is cheap to allocate/copy/destroy, so it's often instantiated on the actual scope stack.
And then there're the data itself, which are allocated on the heap memory, as there may be lot of them, and the pointer to the heap is stored inside the container inner structure.

pick() is sort of "copy constructor", which will copy the size/capacity/pointer from one Vector to the other Vector container, and it will disconnect and invalidate the old container's data pointer. Effectively "moving" the Vector without copying millions of data, only the small constant size Vector container inner structure is copied.

clone() is full copy constructor, which will allocate another (second) block of heap memory for the actual data inside the new Vector instance, and then will copy the actual data from one block of heap memory to the new one.
The old instance of Vector remains fully operational. This is performance expensive operation, and you don't want to do it, unless you actually need a second copy of data.

So when you have a cheap way to move the Vector data around with "pick", you can instantiate Vector inside function, fill it up with data, return the temporary function instantiated Vector (to be released on the very next line after return from function), and pick the data payload to caller's Vector instance, saving them from release, but not copying them one by one.

If you are still confused, which of those two used, use always "pick" in debug mode. In case you mess it up, and access the picked container after, it will crash with some assertion, that you tried to access data from picked Vector, then you can decide if you need a copy, or you accidentally access old Vector instead of the new one.

In case of function returning Vector there's no reason for "clone()", as the source instance is destroyed right away in the function call clean up.


+1

This clear and simple explanation of the pick() and clone() taking vector as an example, should be included in the U++ docs, really. Smile

Regards,

Oblivion


[Updated on: Sat, 23 January 2016 23:02]

Report message to a moderator

Re: Issues using 2015.2 version [message #45913 is a reply to message #45902] Mon, 25 January 2016 09:48 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Really clean and neat explanation, in my local copy of the library I used clone() but indeed a copy of the vector is not necessary, pick() will fit.
Re: Issues using 2015.2 version [message #45925 is a reply to message #45895] Tue, 26 January 2016 23:32 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Mindtraveller wrote on Thu, 21 January 2016 20:16

It's simple: your new compiler is C++11 compiler. And thus U++ is compiled in C++11 mode. It means, among other things, that you must now specify whether you use Pick or Clone operation.
For example, this code is valid for U++ in 'old' mode:
Vector<int> a,b; a = b;

But it fails to compile in U++11 mode because you should use pick/clone and call it explicitly:
Vector<int> a,b; a = pick(b);

Of course, you may use clone() only if your object supports it.
Please refer to the updated Help documentation for details.


Hello,

Very interesting. I am getting a lot of similar errors (C2280) even where old assignment between Vector<> is not apparently involved. For example when Vector<int> is passed in a function. Moreover in my case the pick/clone trick does not work.
Anyway I would like to come back to the old U++ good way and get my code compiled correctly. Does anybody know how to set VC2015 in order to avoid the C2280 error?

Thanks,
Luigi
Re: Issues using 2015.2 version [message #45926 is a reply to message #45925] Wed, 27 January 2016 07:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hi,

I would rather recommend fixing the code. Could you please show me the example of code that is causing the problem?

Note that very often, old behavior masked bugs.

Mirek
Re: Issues using 2015.2 version [message #45928 is a reply to message #45926] Wed, 27 January 2016 21:10 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
mirek wrote on Wed, 27 January 2016 07:27
Hi,

I would rather recommend fixing the code. Could you please show me the example of code that is causing the problem?


Here it is one:

class ReadExcelDlg : public WithReadExcel<TopWindow> {
	typedef ReadExcelDlg CLASSNAME;
	OfficeSheet sheet;
	void MakeList();
	void SaveDetailRecord(int count, int idteam, Vector<String> p);
	int  SaveMasterRecord(Vector<String> t);
public:
	bool updated;
	void SetTournamentDir( String dir);
	void ReadSheetDetail();
	ReadExcelDlg();
};
// code snippet

		Vector<String> t;
                //...
		int idteam = SaveMasterRecord( t); <--- error C2280


another

class Pair : Moveable<Pair> {
public:
	int idw, idb;
	String ToString() const { return AsString(idw) + ' ' + AsString(idb); }
	Pair(int idw, int idb) : idw(idw), idb(idb) {}
	Pair() {}
};

class SortPairing { 
	Vector<Pair> pairs;
	int comppair(int j1, int j2);
 public:
	Vector<Pair> SortPairs(Vector<Pair> pairing);
	SortPairing() {}
	~SortPairing(){;}
};

 	//code snippet
        SortPairing S, pairs;
        //...
  	Vector<Pair> sortedPairing;   
        sortedPairing = S.SortPairs(pairs);  <--- error C2280


There are several of this kind that appear when Vector<something> is passed in a function.
With non C11 everything worked without complain.

Thanks!
Luigi

[Updated on: Wed, 27 January 2016 21:14]

Report message to a moderator

Re: Issues using 2015.2 version [message #45929 is a reply to message #45891] Wed, 27 January 2016 22:42 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Do you really want to pass full copy?

I think for example for "Save" a const reference is much better, i.e.:
int SaveMasterRecord(const Vector<String> & t);

About the sort... you probably want to keep "pairs" intact?
Then you can again use const reference as input for the function.

But maybe you should check for the built-in Sort, like this:
    Vector<int> pairs{1, 4, 2, 3};
    Vector<int> sortedPairs = clone(pairs);
    Sort(sortedPairs, [](const int & a, const int & b){return a < b;} );
    // lambda expression used for simple "a is less than b" predicate here
    // to give you idea, how you can code your own comparator for "Pair" type
    //(the "less than" is default predicate of Upp::Sort(T & container); )


So if you would define operator < in Pair class, you would be able to write:
    Vector<Pair> sortedPairs = clone(pairs);
    Sort(sortedPairs);


Anyway, passing full copy of Vector to function does make little sense to me, only when you actually store the parameter somewhere... but in most cases you want either just to read the data (const Vector & v), or you want to
manipulate them, but the owner of the Vector is still the caller, so you want to operate on his instance: (Vector & v);
Re: Issues using 2015.2 version [message #45937 is a reply to message #45929] Thu, 28 January 2016 15:42 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
mr_ped wrote on Wed, 27 January 2016 22:42
Do you really want to pass full copy?


Hi,

thanks for the answer. That code was a bit old. It never gave problem and I forgot it. You are right of course.
After your observation I cleaned it and used Vector<...>& everywhere.

Now it compiles but fail to link Shocked with error:

index.php?t=getfile&id=4928&private=0

regarding Browser.lib. Does anybody know what is it?

Thanks again,
Luigi

[Updated on: Thu, 28 January 2016 20:18]

Report message to a moderator

Re: Issues using 2015.2 version [message #45949 is a reply to message #45937] Sat, 30 January 2016 14:03 Go to previous message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
forlano wrote on Thu, 28 January 2016 15:42
mr_ped wrote on Wed, 27 January 2016 22:42
Do you really want to pass full copy?


Hi,

thanks for the answer. That code was a bit old. It never gave problem and I forgot it. You are right of course.
After your observation I cleaned it and used Vector<...>& everywhere.

Now it compiles but fail to link Shocked with error:


Solved.
I needed to remove the package Ide/Browser from my project. I do not know how they entered in my package being foreigner.

thank you,
Luigi
Previous Topic: Empty Template vs CtrlLib application with main window
Next Topic: Problem in example code
Goto Forum:
  


Current Time: Thu Mar 28 12:20:45 CET 2024

Total time taken to generate the page: 0.01147 seconds