I am creating a project that reads a file and does some things with the data within the file:
NameSurferDataBase.cpp
#ifndef NAMESURFERDATABASE_CPP
#define NAMESURFERDATABASE_CPP
#include "NameSurferDataBase.h"
#include "linked_list.h"
#include <iostream>
#include <list>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <ostream>
#include <sstream>
#include <iomanip>
#include <istream>
#include <cstdio>
using namespace std;
NameSurferDataBase::NameSurferDataBase(string filename){
getNameData(filename);
}
void NameSurferDataBase::getNameData(string filename){
ifstream input;
input.open(filename);
if(!input.is_open()){
cout << "Not Open";
}else{
string temp;
while(input.is_good()){
getline(input,temp);
if(!input.eof()){
NameSurferEntry entry(temp);
database.InsertInOrder(entry);
}
}
}
}
NameSurferEntry NameSurferDataBase::findEntry(string name){
NameSurferEntry temp(name);
if(database.Search(temp) == true){
return temp;
} else{
cout << "Name not found" << endl;
}
}
#endif
NameSurferDataBase.h
#ifndef NAMESURFERDATABASE_H
#define NAMESURFERDATABASE_H
#include "NameSurferEntry.h"
#include "linked_list.h"
#include <iostream>
#include <list>
#include <string>
class NameSurferDataBase {
public:
NameSurferDataBase(string filename);
void getNameData(string filename);
NameSurferEntry findEntry(string name);
private:
linked_list<NameSurferEntry> database;
};
#endif
Whenever I try to compile, I get the below errors on this line in my main
code:
NameSurferDataBase namesdb = NameSurferDataBase("NamesData.txt");
main.cpp: In function ‘int main()’: main.cpp:19:67: error: use of deleted function ‘NameSurferDataBase::NameSurferDataBase(NameSurferDataBase&&)’ NameSurferDataBase namesdb = NameSurferDataBase("NamesData.txt"); ^ In file included from main.cpp:5:0: NameSurferDataBase.h:11:7: note: ‘NameSurferDataBase::NameSurferDataBase(NameSurferDataBase&&)’ is implicitly deleted because the default definition would be ill-formed: class NameSurferDataBase { ^~~~~~~~~~~~~~~~~~ NameSurferDataBase.h:11:7: error: invalid initialization of non-const reference of type ‘linked_list<NameSurferEntry>&’ from an rvalue of type ‘linked_list<NameSurferEntry>’
Why is it saying my constructor is ill-formed?
You are constructing a temporary NameSurferDataBase
and moving it into namesdb
. A default move constructor cannot be generated due to your use of linked_list
, which likely prohibits moving.
Construct namesdb
directly and it should work, eg:
NameSurferDataBase namesdb("NamesData.txt");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.