///functions.cpp///
#ifndef FUNCTIONS_CPP
#define FUNCTIONS_CPP
#include "functions.h"
#include <iostream>
void print(char* input)
{
cout<<input<<endl;
}
int increment(int a)
{
return (a+1);
}
int sum(int a, int b)
{
return (a+b);
}
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
///main.cpp///
#include "functions.h"
#include <iostream>
int main()
{
print("hello world!");
int foo=5;
int foo2=increment(foo);
cout<<"foo: "<<foo<<endl;
cout<<"foo2: "<<foo2<<endl;
cout<<"sum(foo,foo2): "<<sum(foo,foo2)<<endl;
return 0;
}
This makes sense to me... But when i try compiling main.cpp I get a bunch of "Undefined symbols"
This leads me to think that the functions are not defined...
The program works as expected if I #include "functions.cpp" in main.cpp... but I thought one only had to include the .h file and the linker would link all the symbols for you...