Can't resolve the errors


This is the main file

#include <cstdlib>
#include "Records.h"
#include <vector>
#include <iostream>
#include <array>

using namespace std;

void menu(array<Record, 10> & addressBook);
void recordInput(array<Record, 10> & addressBook);
void displayInfo(array<Record, 10> addressBook);
int main() {
array<Record, 10> addressBook;
menu(addressBook);

return 0;
}
void menu(array<Record, 10> & addressBook)
{
int choice;
cout << "1. Input information into an record." << endl;
cout << "2. Display all information in all records. " << endl;
cout << "3. Exit the program. " << endl;
cin >> choice;

switch(choice)
{
case 1:
recordInput(addressBook);
break;
case 2:
displayInfo(addressBook);
break;
case 3:
cout << "Exiting the program." << endl;
exit(0);
default:
menu(addressBook);
}

}
void recordInput(array<Record, 10> & addressBook)
{
int recordNum, telephoneNum, age;
string firstName, lastName;
for(int i = 0; i < 10; i++)
{
cout << "Enter the record number. " << endl;
cin >> recordNum;
cout << "Enter the telephone number. " << endl;
cin >> telephoneNum;
cout << "Enter the age. " << endl;
cin >> age;
cout << "Enter the first name. " << endl;
cin >> firstName;
cout << "Enter the last name. " << endl;
cin >> lastName;
addressBook[i] = (Record(recordNum, age, telephoneNum, firstName, lastName));
}
menu(addressBook);

}
void displayInfo(array<Record, 10> addressBook)
{
for(int j = 0; j < 10; j++)
{

cout << addressBook[j].getRecordNum() << endl;
cout << addressBook[j].getAge() << endl;
cout << addressBook[j].getTelephoneNum() << endl;
cout << addressBook[j].getFirstName() << endl;
cout << addressBook[j].getLastName() << endl;
cout << "-----------------------------------" << endl;

}
menu(addressBook);
}



This is the header file

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/*
* File: Record.h
* Author: mdustin94
*
* Created on October 5, 2017, 4:09 PM
*/

#ifndef RECORD_H
#define RECORD_H
#include <string>
class Record
{
private:
int recordNum, age, telephoneNum;
std::string firstName, lastName;
public:
Record(int precordNum, int page, int ptelehponeNum, std::string pfirstName, std::string plastName);
int getRecordNum();
int getAge();
int getTelephoneNum();
std::string getFirstName();
std::string getLastName();
};



#endif /* RECORD_H */

This is the Records.cpp file

#include "Records.h"
Record::Record(int precordNum, int page, int ptelephoneNum, std::string pfirstName, std::string plastName)
{
recordNum = precordNum;
age = page;
telephoneNum = ptelephoneNum;
firstName = pfirstName;
lastName = plastName;
}
int Record::getRecordNum()
{
return recordNum;
}
int Record::getAge()
{
return age;
}
int Record::getTelephoneNum()
{
return telephoneNum;
}
std::string Record::getFirstName()
{
return firstName;
}
std::string Record::getLastName()
{
return lastName;
}


Here are the errors


main.cpp: In function 'int main()':
main.cpp:15:23: error: use of deleted function 'std::array<Record, 10ul>::array()'
array<Record, 10> addressBook;
^~~~~~~~~~~
In file included from main.cpp:7:0:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/array:90:12: note: 'std::array<Record, 10ul>::array()' is implicitly deleted because the default definition would be ill-formed:
struct array
^~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/array:90:12: error: no matching function for call to 'Record::Record()'
In file included from main.cpp:4:0:
Records.h:23:9: note: candidate: Record::Record(int, int, int, std::string, std::string)
Record(int precordNum, int page, int ptelehponeNum, std::string pfirstName, std::string plastName);
^~~~~~
Records.h:23:9: note: candidate expects 5 arguments, 0 provided
Records.h:17:7: note: candidate: Record::Record(const Record&)
class Record
^~~~~~
Records.h:17:7: note: candidate expects 1 argument, 0 provided
Records.h:17:7: note: candidate: Record::Record(Record&&)
Records.h:17:7: note: candidate expects 1 argument, 0 provided
make[2]: *** [nbproject/Makefile-Debug.mk:74: build/Debug/Cygwin-Windows/main.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/dusti/OneDrive/Documents/NetBeansProjects/CppApplication_4'
make[1]: *** [nbproject/Makefile-Debug.mk:60: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/dusti/OneDrive/Documents/NetBeansProjects/CppApplication_4'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2



main.cpp:15:23: error: use of deleted function 'std::array<Record, 10ul>::array()'

Add a constructor without arguments in your class.

When you write
array<Record, 10> addressBook;
you instruct the compiler to build a std::array with 10 instances of class Record.
But class Record has got only a constructor, which asks for 5 parameters.
So, or you provide 5 parameters for everyone of the 10 instances of Record, or you provide a constructor which doesn't ask for parameters.
Record() = default;

Please note: the compiler explains that very well:
note: candidate: Record::Record(int, int, int, std::string, std::string)
Record(int precordNum, int page, int ptelehponeNum, std::string pfirstName, std::string plastName);
Records.h:23:9: note: candidate expects 5 arguments, 0 provided


Now, if you wonder why you needed to wait so long to get an answer, I think it could be because you didn't use the 'code' tags:
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/If you don't
If you don't help people to help you, it may happen people could think helping you it's too hard.
Topic archived. No new replies allowed.