header file problems

Hey,

So, I am trying to link two files. The problem is with print()
Error 1 error LNK2005: "void __cdecl print(void)" (?print@@YAXXZ) already defined in score.obj main.obj konsole

Here are the files
score.h
1
2
3
4
5
6
7
8
9
10
11
#pragma once
#define score_h
#include <iostream>

using namespace std;

void print()
{
  cout << "I made it!";
}


main.cpp
1
2
3
4
5
6
7
8
#include "score.h"

using namespace std;

void main()
{
  print();
}


Btw, is it possible to pass declared libraries instead of declaring over and over again them in other header files?
Last edited on
You need to declare print() inline if you are going to implement it in the header file. Otherwise, move the implementation of print() to a .cpp file.
Topic archived. No new replies allowed.