Hello,
So I am working on a simple phonebook app using file reading/writing, but in my Phonebook class constructor I am having issues. For some reason it is not allowing me to pass a string argument to the constructor. I took out the argument in the definition and declaration and it compiled fine and ran so I know that is where the issue is.
The error message is "C2664 'Phonebook::Phonebook(Phonebook &&)': cannot convert argument 1 from 'std::string' to 'const Phonebook &' MyPhonebook c:\users\brandon\documents\visual studio 2015\projects\myphonebook\myphonebook\main.cpp 30" and it doesn't make any sense to me. I googled the error message and I am passing a string to the constructor not any other type. I also get another error message saying "C4430 missing type specifier - int assumed. Note: C++ does not support default-int MyPhonebook c:\users\brandon\documents\visual studio 2015\projects\myphonebook\myphonebook\person.h 14"
Can someone please help me see what is happening? I would greatly appreciate it!
Phonebook.h
#pragma once
#include "LibIncludes.h"
class Phonebook
{
public:
Phonebook(string tmp_pb_name);
void addEntry();
void deleteEntry();
void searchByFirstName() const;
void searchByNumber() const;
void displayAllEntries() const;
void clearAllEntries();
int mainMenu();
private:
string phonebook_name;
};
Phonebook.cpp
///////////////////////////////////////
//
// Phonebook definitions
//
///////////////////////////////////////
#include "LibIncludes.h"
Phonebook::Phonebook(string tmp_pb_name)
{
phonebook_name = tmp_pb_name;
}
//--------------------------------------------------------------------
int Phonebook::mainMenu()
{
int option = 0;
do
{
system("CLS");
cout << "\n\n\t\t-----" << phonebook_name << " Phonebook-----";
cout << "\n\t\t|";
cout << "\n\t\t|\t[1] Create New Entry";
cout << "\n\t\t|\t[2] Delete Entry";
cout << "\n\t\t|\t[3] Display ALL Entries";
cout << "\n\t\t|\t[4] Search By FIRST Name";
cout << "\n\t\t|\t[5] Search by PHONE NUMBER";
cout << "\n\t\t|\t[6] Clear ALL Entries";
cout << "\n\t\t|\t[7] Exit Your Phonebook";
cout << "\n\t\t|----------------------------------------------";
cout << "\n\n\t\t> ";
cin >> option;
if (option < 1 || option > 7)
{
cout << "\n\t\t*** [ Error! Option Out Of Range! ] ***\n";
system("PAUSE");
}
} while (option < 1 || option > 7);
return option;
}
//--------------------------------------------------------------------
void Phonebook::addEntry()
{
}
//--------------------------------------------------------------------
void Phonebook::displayAllEntries() const
{
}
//--------------------------------------------------------------------
void Phonebook::clearAllEntries()
{
}
//--------------------------------------------------------------------
void Phonebook::deleteEntry()
{
}
//--------------------------------------------------------------------
void Phonebook::searchByFirstName() const
{
}
//--------------------------------------------------------------------
void Phonebook::searchByNumber() const
{
}
Main.cpp
///////////////////////////////////////
//
// Basic phonebook app that
// uses writing and reading
// from files for the data
// entries
//
//////////////////////////////////////
#include "LibIncludes.h"
string setPhoneBookName()
{
string name;
cout << "\n\n\n\n\t\t\t\t-----Please Enter In Your Desired Phonebook Name-----";
cout << "\n\t\t\t\t> ";
cin >> name;
return name;
}
//---------------------------------------------------------------------------------------
int main()
{
int user_option = 0;
bool exit = false;
Phonebook myBook(setPhoneBookName());
while (user_option != 7)
{
while (!exit)
{
user_option = myBook.mainMenu();
switch (user_option)
{
case 7:
cout << "\n\n\t\t---------------Goodbye---------------\n";
cout << "\t\t";
system("PAUSE");
exit = true;
break;
default:
cout << "\n*** [ Invalid Option! ] ***\n";
}
}
}
return 0;
}
LibIncludes.h
/////////////////////////////////////
//
// All header files needed
//
/////////////////////////////////////
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include "Person.h"
#include "Phonebook.h"
using namespace std;