Error - attempting to reference a deleted function

I have an error related to class - I am using Visual studio - It is saying the class was deleted but the function does exist.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 #include "stdafx.h"
#include "Input_Data.h"
#include"System_Limit.h"
#include<complex>
#include<vector>
#include<math.h>
#include <iostream>
#include"LFL_Class.h"

using namespace std;


int main()
{
	LFL_Class LF;

	LF.getdatainput();
	    
	//cout << LF.eps << endl;

	system("pause");

	return 0;


}


Error : 1>------ Build started: Project: MPSA, Configuration: Debug Win32 ------
1>MPSA.cpp
1>c:\mpsa\mpsa\mpsa\mpsa.cpp(18): error C2280: 'LFL_Class::LFL_Class(void)': attempting to reference a deleted function
1>c:\mpsa\mpsa\mpsa\lfl_class.h(1187): note: compiler has generated 'LFL_Class::LFL_Class' here
1>c:\mpsa\mpsa\mpsa\lfl_class.h(1187): note: 'LFL_Class::LFL_Class(void)': function was implicitly deleted because a data member invokes a deleted or inaccessible function 'Input_Data::Input_Data(void)'
1>c:\mpsa\mpsa\mpsa\input_data.h(280): note: 'Input_Data::Input_Data(void)': function was implicitly deleted because 'Input_Data' has an uninitialized const-qualified data member 'Input_Data::nLine'
1>c:\mpsa\mpsa\mpsa\input_data.h(57): note: see declaration of 'Input_Data::nLine'
1>Done building project "MPSA.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Need to see LFL_Class.h, Input_Data.h and System_Limit.h, as well as any .cpp files related to them.
Last edited on
It is saying the class was deleted but the function does exist.

Not the class, but the default constructor.

You possibly have a class like this:
struct Input_Data { const int nLine ; };

Since you haven't defined any special member functions, the compiler will try to generate a default constructor for that class if you use it. That implicitly-defined default constructor would be exactly like this one:
 
Input_Data::Input_Data() {}

However, that code is ill-formed (wrong), because it leaves nLine un-initialized. Since the compiler won't write you code that doesn't compile, it instead forbids you from ever calling it by deleting the implicitly-defined default constructor instead:
Input_Data() = delete;

The error message is telling you you're using this deleted default constructor in the default constructor of LFL_Class, possibly by doing something like Input_Data a; instead of Input_Data a { 42 };
Last edited on
Hello,

Thank you for your explanation - I am not sure about constructor, may be the way i am defining and using the class function is not correct.

This is all about how to use a class array function in VS.


ZY_Cal : class function, will be called in Input_Data class to perform calculation. Function will be called as follow: ZY_Cal Line[var], and function to be called Line[var].GetLinePU (...)

var should be Constant variable as per VS. Var should be defined as the number of lines as input.

The system can have many lines (number is defined as nLine). Since nLine is normally > 1, i am defining as many class functions as I need:


In summary:
in Input_Data class :

const int nLine = 3;
ZY_Cal Line[nLine];
vector<double> Z;

for (i=0; i<nLine, i++){ Z(p) = Line[p].GetLinePU(....)};


This a simplified version of class ZY_Cal:

#include<complex>
#include<vector>
#include<math.h>
using namespace std;

class ZY_Cal {

public:

double Zx;

double GetLinePU(double MVA, double V)

{

Zx = V*V/MVA;
return Zx;

}

};


This a simplified version of class Input_Data :

#include<complex>
#include<vector>
#include<math.h>
#include "ZY_Cal.h"
#include <iomanip>
#include <iostream>

using namespace std;

class Input_Data {

public:

vector<double> Z;
const int nLine;

double FBranch() {


const int nLine = 3;
Z.resize(nLine);

ZY_Cal Line[nLine];


double MVAx[] = { 11 11 11};
double Vpx[] = { 11 11 11};



for (int p = 0; p < nLine; p++) {

Z[p]=Line[p].GetLinePU(MVAx[p], Vpx[p]);}


return 0;


}

};
By just replacing nLine by a number the error vanished:

Instead of

ZY_Cal Line[nLine];

I used :

ZY_Cal Line[3];

But this is not what i want to do: nLine is an input defined by user and should be define in one place.



In accordance with the C++ standard, you can't use dynamic (user) input for the size of arrays.

If you need dynamic array sizes, you should use C++ std::vector.

Instead of
ZY_Cal Line[nLine];
do
std::vector<ZY_Cal> Line(nLine);

Be sure to #include <vector> at the top of your file.

This creates an std::vector with nLine number of lines.
You can access each element in the same way, i.e. Line[0], Line[1], etc.
Last edited on
Hello,

The problem is resolved now and the algorithm is back running as before under VS (it was developed under Clion IDE).

My next step is to try to program a window in VS, that have a library of electrical components like, bus, Line, Generator, transformer, etc... The user will drag any component on the screen and draw a single line diagram (Like one Generator1 connected to a bus1, a line will be connected between bus1 and bus2, a load L1 will be connected to bus2). Each shall have shall have a data input window for data entry. All data entered shall be linked to the algorithm for calculation...it should be very similar to product developed by the following:

http://www.ucancode.net/ELECTROIC_POWER_VC_DELPHI_SOURCE_CODE.htm


I never used the VS windows programming - But I want to learn and built my own Power system software and start my dream project.

I want to know where to start, how to learn programming, training etc...

Thank

This is an example of the calculation results for 3 buses, 2 generator and 2 loads

Vi(0) = (1.05,0)
|Vi|: 1.05
<Vi: 0
Vi(1) = (1.04625,-0.0108843)
|Vi|: 1.0463
<Vi: -0.59604
Vi(2) = (1.04812,-0.00544219)
|Vi|: 1.04814
<Vi: -0.297495
Bus injected MW/MVAR (1) = (120,40.271)
Bus injected MW/MVAR (2) = (-120,-40)
Bus injected MW/MVAR (3) = (0,0)
S MW/MVAR (1) = (120,41.3919)
S MW/MVAR (2) = (-120,-39.9999)
S MW/MVAR (3) = (-0.000255253,-4.53517e-05)
Load on Bus MW/MVAR (1) = (200,100)
Load on Bus MW/MVAR (2) = (200,100)
Generator(0) MW on bus # 1 = (320,140.271)
Generator(1) MW on bus # 2 = (80,60)
Line Flow = (0,1)(11.4286,3.94208) Line Flow = (1,0)(-11.4286,-3.80952) Line Losses = (0,1)(0,0.132564)
Line Flow = (0,2)(5.7143,1.97104) Line Flow = (2,0)(-5.7143,-1.9379) Line Losses = (0,2)(0,0.0331413)
Line Flow = (1,2)(-5.71426,-1.90476) Line Flow = (2,1)(5.71426,1.9379) Line Losses = (1,2)(0,0.0331409)
Total line Line Losses = ((0,0.198846)
Line chanrging(0) MW/MVAR on bus # 1 = (0,0)
Line Disipation (0) MW/MAR on bus # 1 = (0,0.132564)
Line chanrging(1) MW/MVAR on bus # 1 = (0,0)
Line Disipation (1) MW/MAR on bus # 1 = (0,0.0331413)
Line chanrging(2) MW/MVAR on bus # 2 = (0,0)
Line Disipation (2) MW/MAR on bus # 2 = (0,0.0331409)
Total Load MW/MVAR = (400,200)
Total Geneartion MW/MVAR = (400,200.271)
Generation - Load MW/MVAR = (0,0.270978)
Total Line Disipation = (0,0.198846)
Total Line Charging = (0,-0)

Mis_match = (0,0.0721318)
Press any key to continue . . .





Last edited on
Topic archived. No new replies allowed.