The default Constructor of "input" cannot be referenced -- it is a deleted function

Hello, I am supposed to make a program in which I will be using Struct variables in Union. However, when I use Union, it shows me the error that its default constructor cannot be referenced.
I tried searching the issue on internet but I couldn't find a good solution. At one place, it was written that this is some compiler bug and it will be fixed with the update of Visual Studio 2015. However, I am using Visual Studio 2017 Enterprise and I am still facing this issue..
Can anyone help me resolve the issue, please?
Here is the code of my program.

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<string>
using namespace std;
struct student {
	string name;
	int roll;
	float gpa;
};
struct faculty {
	string name;
	int id;
	int salary;
};
enum type { stu, fac };
union record {
	student s;
	faculty f;
};
struct input {
	type t;
	record r;

};
int main()
{
	input in;
	cout << "New Entry" << endl
		<< "Press (0) for Student" << endl
		<< "Press (1) for Faculty" << endl
		<< "Your Choice: ";
	int h;
	cin >> h;
	in.t = (type)h;
	if (in.t == 0)
	{
		cout << endl << "Student Database" << endl
			<< "Enter Name: ";
		getline(cin, in.r.s.name);
		cout << "Enter GPA: ";
		cin >> in.r.s.gpa;
		cout << "Enter Roll Number: ";
		cin >> in.r.s.roll;
	}
	else if (in.t == 1)
	{
		cout << endl << "Faculty Database" << endl
			<< "Enter Name: ";
		getline(cin, in.r.f.name);
		cout << "Enter ID: ";
		cin >> in.r.f.id;
		cout << "Enter Salary: ";
		cin >> in.r.f.salary;
	}
	cout << endl;
	system("pause");
	return 0;
}


A union may not contain anything that does not have a trivial copy constructor. You could think of this as meaning anything that cannot simply be copied byte-for-byte.

A std::string does not have a trivial copy constructor, so you're not allowed one in a union.

https://stackoverflow.com/questions/7299171/union-member-has-a-non-trivial-copy-constructor?rq=1
Got it, thank you very much! ^_^
Topic archived. No new replies allowed.