I am writing a simple class and get some error. The header file is shown below:
//
// temp.h
//
#ifndef _TEMP_h
#define _TEMP_h
#include <string>
using namespace std;
class GameEntry {
public:
GameEntry(const string &n="", int s=0);
string getName();
int getScore();
private:
string name;
int score;
};
#endif
And the method file is shown below:
// temp.cpp
#include "temp.h"
#include <string>
using namespace std;
GameEntry::GameEntry(const string &n, int s):name(n),score(s) {}
string GameEntry::getName() { return name; }
int GameEntry::getScore() { return score; }
The main file is shown below:
#include <iostream>
#include <string>
#include "temp.h"
using namespace std;
int main() {
string str1 = "Kenny";
int k = 10;
GameEntry G1(str1,k);
return 0;
}
I got error like this:
Undefined symbols for architecture x86_64:
"GameEntry::GameEntry(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> > const&, int)", referenced from:
_main in main1-272965.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone tell me what's wrong? Many thanks.