xcode - Undefined symbols for architecture x86_64: c++ -
i'me getting error in xcode undefined symbols architecture x86_64: "restaurant::restaurant()", referenced from: _main in main.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation)
this 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.
you have following methods declared:
restaurant(); int gettables(); int gettempstaff(); int getpermstaff(); string getshifts(); string getmenu(string menu);
.. , you've defined restaurant::getmenu
below. problem here although you've declared restaurant::restaurant
(the constructor), haven't defined it.
but that's true of restaurant::getshifts
, why aren't getting error aswell?
it's because constructor automatically called when object of type being created, here:
//.. restaurant mimmos; //..
. never end trying call restaurant::getshifts
(or other non-constructor methods matter) there's no error.
you can define constructor default (which allows compiler make sensible 1 you) other answer-er said or can define own, seem want anyway.
Comments
Post a Comment