Here is a toy fruit class. If I compile it I get the error:
Undefined symbols for architecture x86_64:
"fruit::fruit(std::string, std::string, float)", referenced from:
_main in cpptest-bglXKK.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I omit lines 48-50 it works. What is happening?
First of all, you forgot to include the string header, as in #include <string> .
The minor things are: 1) You are using the assignment operator without defining it yourself (a default one is generated anyway). 2) You could write simply int main() if you don't need the command line arguments. 3) The return 0; at the end is not needed (special case for main() function).
Back to assignment, your fruit should rather look like:
1 2 3
fruit fig;
// ...
fruit apple("red", "round", 2.0);
I still cannot get this to work. It works fine until I add line 46.
Undefined symbols for architecture x86_64:
"fruit::fruit(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, float)", referenced from:
_main in cc11pDrQ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status