Hello!
I'm just practicing using classes in separate files. My output should be "I am a banana!", but instead I get nothing when I run my compiled code.
I'm really not sure what I'm doing incorrectly. (All three files are in the same directory) Any input would be much appreciated.
main.cpp:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include "Apple.h"
usingnamespace std;
int main(){
Apple appleObject;
return 0;
}
Oh, I assumed that the Banana function would automatically run because Apple::Banana was a constructor for the class, so when I created the appleObject, it would run Banana.
I added appleObject.Banana(); to the main function and then I added void in front of Apple::Banana and I got the error:
main.cpp(.text+0x11): undefined reference to 'Apple::Banana()'
collect2: ld returned 1 exit status