Reputation: 85
i'me getting the error in xcode Undefined symbols for architecture x86_64: "Restaurant::Restaurant()", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is my code:
#include <iostream>
using namespace std;
class Restaurant
{
public:
Restaurant();
int getTables();
int getTempStaff();
int getPermStaff();
string getShifts();
string getMenu(string menu);
private:
string Menu;
int Tables;
int TempStaff;
int PermStaff;
string Shifts[3];
};
string Restaurant::getMenu(string menu)
{
Menu = menu;
return menu;
}
int main()
{
Restaurant mimmos;
string Menu;
cout<<"Menu: ";
cin>>Menu;
cout<<mimmos.getMenu(Menu);
return 0;
}
Please help.
Upvotes: 2
Views: 2560
Reputation: 496
You have the following methods declared:
Restaurant();
int getTables();
int getTempStaff();
int getPermStaff();
string getShifts();
string getMenu(string menu);
.. and you've defined Restaurant::getMenu
below. The problem here is that although you've declared Restaurant::Restaurant
(the constructor), you haven't defined it.
But that's true of Restaurant::getShifts
, why aren't you getting an error with that aswell?
It's because the constructor is automatically called when an object of that type is being created, like here:
//..
Restaurant mimmos;
//..
. You never actually end up trying to call Restaurant::getShifts
(or the other non-constructor methods for that matter) so there's no error.
You can define the constructor to be default (which allows your compiler make a sensible one for you) as the other answer-er said or you can define your own, which is what you seem to want to do anyway.
Upvotes: 1
Reputation: 19771
class Restaurant {
Restaurant() = default;
...
};
will give you the default constructor for Restaurant.
Upvotes: 1