0

I'm still trying to get to grips with C++ and I understand the idea and use of header files, but every time I try and implement one I get the same error every time

Undefined symbols for architecture x86_64:
"Maths::addnumber(int, int)", referenced from:
  _main in main-3adee4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)

I'm just trying to make it work at the minute with just a very basic add method just to actually make a header file work really but no matter what I've read so far I can't seem to fix it. Any help would be amazing thanks!

This is my tester.cpp

#include "tester.hpp"
using namespace std;

int Maths::addnumber(int x, int y)
{
    int ans = x + y;
    return ans;
}

This is my tester.hpp

#ifndef tester_hpp
#define tester_hpp

#include <stdio.h>


class Maths
{
public:
    int addnumber(int x, int y);

};


#endif /* tester_hpp */

This is my main.cpp file

#include <iostream>
#include "tester.hpp"
using namespace std;

int main()
{
    Maths test;
    test.addnumber(10,20);



    return 0;
}
user207421
  • 305,947
  • 44
  • 307
  • 483
Nazat
  • 1

0 Answers0