0

here is my code I get an error everytime I run it saying undefined reference to Maths::add I am using VScode with the code runner extension the command that they provide is cd "c:\Users\sethz\OneDrive\Desktop\G++" ; if ($?) { g++ main.cpp -o main } ; if ($?) { .\main }

main.cpp

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

int main()
{
    Maths maths;
    maths.add(5, 7);
}

maths.hpp

#ifndef MATHS_HPP
#define MATHS_HPP

class Maths
{
public:
    void add(float num1, float num2);
};
#endif

maths.cpp

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

void Maths::add(float num1, float num2)
{
    cout << num1 + num2;
}

Can somebody please tell me how to fix it if you know how because I've been trying to header files in C++

0 Answers0