Home » Community » Newbie corner » Issues using 2015.2 version
Issues using 2015.2 version [message #45891] |
Thu, 21 January 2016 11:31  |
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   |
|
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 #45894 is a reply to message #45893] |
Thu, 21 January 2016 18:34   |
Lance
Messages: 656 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
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 #45902 is a reply to message #45891] |
Sat, 23 January 2016 12:08   |
mr_ped
Messages: 826 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   |
Oblivion
Messages: 1202 Registered: August 2007
|
Senior Contributor |
|
|
mr_ped wrote on Sat, 23 January 2016 13:08I 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. 
Regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 23 January 2016 23:02] Report message to a moderator
|
|
|
|
|
|
Re: Issues using 2015.2 version [message #45928 is a reply to message #45926] |
Wed, 27 January 2016 21:10   |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
mirek wrote on Wed, 27 January 2016 07:27Hi,
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   |
mr_ped
Messages: 826 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);
|
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 15:09:15 CEST 2025
Total time taken to generate the page: 0.03907 seconds
|