How is it right to determine the operation that the compiler didn't leave the warning?
-
Tell me, please, how can you correct that mistake? The point is that he created his class, he's identified operations as a result of operations, returning the class object that was built inside. The following error, the accusator, the operation and the definition of the class, led to the exercise of functions that might affect the occurrence of the error. I don't know what the problem is.
Mistake
functions.cpp: In member function 'IntPlaneSet IntPlaneSet::operator^(const IntPlaneSet&)':
14:06functions.cpp:58:12: error: implicitly-declared 'constexpr IntPlaneSet::IntPlaneSet(const IntPlaneSet&)' is deprecated [-Werror=deprec ated-copy] 58 | return r; | ^ functions.cpp:30:14: note: because 'IntPlaneSet' has user-provided 'IntPlaneSet& IntPlaneSet::operator=(const IntPlaneSet&)' 30 | IntPlaneSet& IntPlaneSet::operator=(const IntPlaneSet& a) | ^~~~~~~~~~~
Appropriation operator
IntPlaneSet& IntPlaneSet::operator=(const IntPlaneSet& a)
{
SetZero();
CopyOnly(a);
return *this;}
Operation
IntPlaneSet IntPlaneSet::operator^(const IntPlaneSet& a)
{
IntPlaneSet r = IntPlaneSet(max(this->x1,a.x1),max(this->x2,a.x2),max(this->y1,a.y1),max(this->y2,a.y2));
r.b_s = this->b_s ^ a.b_s;
return r;
}Class
#pragma once
#include <cstdio>
#include <cmath>
#include <bitset>
#include <iostream>
#include <cstdlib>
#include <random>
#define x_1 -10
#define y_1 -10
#define x_2 -10
#define y_2 10
#define x_3 10 //допустимые границы, в которых можно задать множество задаются жестко в начале программы
#define y_3 -10
#define x_4 10
#define y_4 10
#define x_size x_3 - x_1 + 1
#define y_size y_2 - y_1 + 1
#define SIZE (x_size)*(y_size)//размер bitset
#define TEST 2 //число массивов в тестеusing namespace std;
class IntPlaneSet
{
int x1,x2,y1,y2;
public:bitset<SIZE> b_s; class iterator { int cur; IntPlaneSet* S; public: iterator(IntPlaneSet *a= NULL) { if (a!=NULL) { this->cur = a->FirstNonZero(); this->S = a; } else { this->cur = -1; this->S=NULL; } } int operator!=(const iterator &b); int operator==(const iterator &b); void operator++(); void operator++(int); pair<int, int> operator*(); }; IntPlaneSet(int x1=x_1,int x2=x_3,int y1=y_1, int y2=y_2,int rand_key = 0 ) { this->x1=x1; this->x2=x2; this->y1=y1; this->y2=y2; this->b_s=( 0 ); if (rand_key == 1) { std::random_device rd; std::mt19937 rng(rd()); std::uniform_int_distribution<int> ValsX(x1,x2); std::uniform_int_distribution<int> ValsY(y1,y2); for(int i = 0;i<abs(x2-x1)*abs(y2-y1);i++) { int x=ValsX(rng); int y = ValsY(rng); int index = ((y - y_1)*((x_3 - x_1)+1)) + ((x - x_1)); this->b_s[index]=1; } } } ~IntPlaneSet() { this->SetZero(); } void SetZero() { this->b_s = ( 0 ); } pair<int, int> GetValue(int a); void AddValue(const int x,const int y); void DeleteValue(const int x,const int y); void Print() { int index=0; cout << "Bitset : ( "<< this->b_s << " )\n"<< endl; for(int i=y_2;i>y_1-1;i--) { for (int j=x_1;j<x_3+1;j++) { index = ((i - y_1)*((x_3 - x_1)+1)) + ((j - x_1)); cout << this->b_s[index] << " "; } printf("\n"); } } void Check(const int x,const int y); int* Borders(); void ChangeBorders(int x1, int x2, int y1, int y2); void ChangeBorders(int* a); int** MinMax(); IntPlaneSet operator&(const IntPlaneSet& a); IntPlaneSet operator|(const IntPlaneSet& a); IntPlaneSet operator^(const IntPlaneSet& a); IntPlaneSet operator~(); void CopyOnly(const IntPlaneSet& a); IntPlaneSet& operator=(const IntPlaneSet& a); int FirstNonZero(); int NextNonZero(int a); iterator begin() { return iterator(this); } iterator end() { return iterator(NULL); }
};
-
You wrote for your class a trainer and a copycat operator, but you didn't write a copying designer, and moving the designer and the transfer operator.
So...
Thank Howard Hinnant for the table.The compiler therefore did not generate moving operations (5.6 columns).
But the replicator sgenerated (3 columns), although it is considered obsolete (deprecated), starting with C++11.
And you used this copying designer somewhere, so the compiler of you warns that it's not worth it.
The decision is to remove the improvised designer and copy the award. They don't do anything useful anyway.
If there was something useful in them, that's another option: obviously ask the compiler to generate missing transactions.
IntPlaneSet(const IntPlaneSet &) = default; IntPlaneSet(IntPlaneSet &&) = default; // IntPlaneSet &operator=(const IntPlaneSet &) = default; IntPlaneSet &operator=(IntPlaneSet &&) = default; // ~IntPlaneSet() = default;
To read https://en.cppreference.com/w/cpp/language/rule_of_three ♪
People ' s wisdom states that the class must have a choice:
- Trainer and coping (all 3)
- Tractor and coping and moving operations (total 5)
- None of five is the most common option (0)
And if the combination is different, it's almost always a mistake, like in your case.