Messing around in C++ for class and came across a error stating that i was trying to reference a deleted function. Here is the error
C2280(Test &Test::operator = (const Test& : attempting to reference a deleted function).
Here is my code:
#include "pch.h"
#include <iostream>
using namespace std;
class Test {
public:
int size;
double* array;
public:
Test();
Test& operator=(Test&& a);
Test(int sizeArg) {
size = sizeArg;
array = new double[size];
}
Test(Test&& arg) {
size = arg.size;
array = arg.array;
arg.size = 0;
arg.array = nullptr;
}
~Test()
{
if (array != nullptr) {
delete[]array;
}
}
};
int main()
{
Test outTest;
int x = 1;
//Wont work since looking for a deleted function
if (x = 1) {
Test arg(200000000);
outTest = arg;
}
cout << outTest.array;
}
The problem is in the main()
on the equal sign.