(Can/How do) you include a header file into two different functions that will be compiled into the same program?! ex...
// main.c
#include <iostream>
#include "cat.h"
using namespace std;
int main()
{
cat spot;
spot.age = 2;
printage(spot);
return 0;
}
//printage.c
#include cat.h"
#include <iostream>
using namespace std;
void printage(cat fluffy)
{
cout << fluffy.age << '\n';
return;
}
//cat.h
class cat
{
int age;
};
cat::cat()
{
age = 0;
}
When this is compiled, it throws out the errors:
/tmp/ccN6V3Pd.o: In function 'cat::cat[not-in-charge]()':
/tmp/ccN6V3Pd.o(.text+0x0): multiple definition of 'cat::cat[not-in-charge]()'
/tmp/ccQuUmOM.o: (.text+0x0): first defined here
/tmp/ccN6V3Pd.o: In function 'cat::cat[in-charge]()':
/tmp/ccM6V3Pd.o(.text+0x68): multiple definition of cat::cat[in-charge]()'
/tmp/ccQuUmOM.o(.text+0x68): first defined here
collect2: ld returned 1 exit status
The command I use to compile is: g++ main.c printage.c -o main
I'm using RedHat 8.0 with gcc3.2.