I have a function “PrintHeader” for my project, defined in io.cpp. Even though io.h is included in my main file, I get the error
error C3861: 'PrintHeader': identifier not found.
When I copy the function for PrintHeader into my main file, I get the errors
error LNK2005: 'void _cdeci PrintHeader(void)" (?PrintHeader@@YAXXZ) already defined in io.obj.
and
error LNK1169: one or more multiply defined symbols found.
I can understand the second error set, since I do have it defined twice, but I don’t understand why it doesn’t work when I just remove the duplicate definition. Any help is greatly appreciated.
Main file
#include "stdio.h"
#include <iostream>
#include "io.h"
void PrintHeader()
{
cout << endl;
cout << "Month\tPrincipal\t Interest\t Balance" << endl;
cout << "-----\t---------\t---------\t---------" << endl;
}
int main()
{
cout << "Hello World\n";
PrintHeader();
getchar();
return 0;
}
io.cpp
#include <iostream>
#include <iomanip>
#include "io.h"
void PrintHeader (void)
{
cout << endl;
cout << "Month\tPrincipal\t Interest\t Balance" << endl;
cout << "-----\t---------\t---------\t---------" << endl;
}
io.h
#ifndef __IO_H__
#define __IO_H__
#include <string>
using namespace std;
void PrintHeader (void);
#endif
You are most likely including the wrong file in main.cpp. You can make sure it is the right file by right clicking on the
include "io.h"and choosing open file.