I have recently started learning c++ and until now I haven’t had too much trouble. However always when I try to use a .h and .cpp file I get an error. I have checked several times if my code has any syntaxe errors but can’t find any. As I am very new to programming I am not sure what I should change based on the error message I get.
I would be very happy if someone could help.
main file
#include
#include"Sally.h"
using namespace std;
int main(){
Sally sallyObject;
Sally *sallyPointer = &sallyObject;
sallyObject.printCrap();
sallyPointer->printCrap();
}
Sally.h
#ifndef SALLY_H
#define SALLY_H
class Sally
{
public:
Sally();
void printCrap();
protected:
private:
};
#endif
Sally.cpp
#include<Sally.h>>
#include
using namespace std;
Sally::Sally()
{
}
void Sally::printCrap(){
cout<<“did someone say steak?”<<endl;
}
error I get
Undefined symbols for architecture x86_64:
“Sally::printCrap()”, referenced from:
_main in arrow member selection operator-36056e.o
"Sally::Sally()", referenced from:
_main in arrow member selection operator-36056e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)