Hi! I'm just trying to create a simple class using header a file and I'm encountering an error every time I compile. The error is "Undefined symbols for architecture x84-64" and lists my functions that implement the methods. Here's the code:
And where are you including <string>? I'd recommend in your account.h file, before the class declaration.
Once that is fixed you have another rather nasty bug lurking. You are not setting the account balance when creating the account object. That leads to very weird account balance:
Name: Bob
Balance: $-92559631349317830736831783200707727132248687965119994463780864.00
Thanks for the replies. I've added #include <string> to Account.h and recompiled, yet I still get the error:
Undefined symbols for architecture x86_64:
"Account::getBalance()", referenced from:
_main in class-25f06d.o
"Account::deposit(double)", referenced from:
_main in class-25f06d.o
"Account::getName()", referenced from:
_main in class-25f06d.o
"Account::setName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in class-25f06d.o
"Account::withdraw(double)", referenced from:
_main in class-25f06d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation
And where are you including <string>? I'd recommend in your account.h file, before the class declaration.
That is indeed where I chose to include.
it isn't even close to being correct
Thank you for correcting this; I hadn't noticed because my program gave the desired output, presumably due to a compiler-specific implementation (I use g++).
I hadn't noticed because my program gave the desired output, presumably due to a compiler-specific implementation
^^^ This is the main reason why I use more than one compiler/IDE. So little things like differing implementation details make spotting logic/run-time errors easier.