Implementation File vs Header File

I have written my program and it works when I keep everything in the header files, and then have my main. I am now splitting them up into implementation files, but Eclipse keeps giving me errors. It gives me error at every opening brace of the constructor and functions. It says on all of them "Redefinition of (name of constructor or method), Previously declared here." What am I doing wrong, because it works in the header file?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "KeyValuePair.h"

template<typename Key,typename Value>
KeyValuePair<Key,Value>::KeyValuePair()
{ // error here
}

template<typename Key,typename Value>
void KeyValuePair<Key,Value>::setPair(Key key, Value value)
{ // error here
	pairKey = key;
	pairValue = value;
}

template<typename Key,typename Value>
Key KeyValuePair<Key,Value>::getKey() const
{ // error here
	return pairKey;
}

template<typename Key,typename Value>
Value KeyValuePair<Key,Value>::getValue() const
{ // error here
	return pairValue;
}
Do you have include guards?
What do you mean? If you mean

1
2
3
4
5
6
#ifndef KEYVALUEPAIR_H_
#define KEYVALUEPAIR_H_

...
#include"KeyValuePair.cpp"
#endif 

Yes I have this in my header file
Last edited on
Yes I meant those.

Did you delete the definitions from the header files?
Topic archived. No new replies allowed.