Gabriel Valedon Gabriel Valedon - 13 days ago 5
C++ Question

Header Files with Source Files C++

I am trying to implement Header Files with Source Files using C++, but in the terminal the give me some errors.

Here is the code:

main.cpp

#include <iostream>
#include "add.h"
using namespace std;

int main()
{
cout << "The Sum of 3 and 4 is: " << add(3,4) << endl;
return 0;
}


add.cpp

int add(int x, int y)
{
return (x + y);
}


add.h

#ifndef ADD_H
#define ADD_H

int add(int x, int y);

#endif


Terminal Messages:
Terminal Messages

Answer

You did use the C-compiler. The warning tells you that you provide C++-code to the C-compiler. In case you want to get rid of this warning, try clang++ -o add.o add.cpp followed by clang++ -o HeaderTest main.cpp add.o

Comments