I am sure this question has be asked and answered million times but I am really clueless. As a newbie to C++ I have created three textbook files.
Num.h
#ifndef LIB_DATE_H
#define LIB_DATE_H
class Num
{
private:
int num;
public:
Num(int n);
int getNum();
};
#endif
Num.cpp
#include "Num.h"
Num::Num(int n) : num(n) {}
int Num::getNum()
{
return num;
}
main.cpp
#include <iostream>
#include "Num.h"
using namespace std;
int main()
{
Num n(35);
cout << n.getNum() << endl;
return 0;
}
Both g++ and clang complain about undefined reference to Num::Num(int)
and Num::getNum()
.
When joining the three files into a single one, no errors are reported by g++; clang is still complaining.
I have managed to google out that this is a problem with linking but I was not able to find any actionable advice to fix it...