beginner problem with class

Hi,

I'm writing a simple program with seperate header, implimintation, and main files. I understand the concept of objects and classes. I just think I don't understand the syntax or which files to include can anyone see what is causeing my error? I think it has to do with the includes but I've tried different ways and can't get rid of the error.

Thanks and I hope it's not a problem that I posted all the code. Sorry if it is. Let me know and I won't do it next time.

1
2
3
4
error:

dayOfWeekImp.obj : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall dayOfWeek::getDay(void)" (?getDay@dayOfWeek@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in dayOfWeekMain.obj


dayOfWeek.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef DAYOFWEEK_H
#define DAYOFWEEK_H

#include <iostream>
#include <string>

using std::string;

class dayOfWeek
{
public:
	void setDay(string);
	string getDay();
	void printDay();

private:
	string day;


};
#endif


dayOfWeekMain.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include <iostream>
#include <string>
#include "dayOfWeek.h"
#include "dayOfWeekImp.cpp"



using std::cin;
using std::cout;
using std::string;
using std::endl;

int main()
{
	
	//declare object (weekDay)
	//and string variable for testing
	dayOfWeek weekDay;
	string today;

	//call the setDay() function
	weekDay.setDay("Mon");

	//get the day with getDay() function
	today = weekDay.getDay();

	//Test the getDay() function
	cout << "Testing the getDay() function. . . " << endl;
	cout << "The function, getDay() returned " << today << " as the day." << endl;

	//call printDay to print the private data member (day)
	weekDay.printDay();

	//hold screen
	system("pause");

//end main
return 0;

}


dayOfWeekImp.cpp

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
27
28
//Implimentation file for dayOfWeek class functions

#include <iostream>
#include <string>
#include "dayOfWeek.h"

using std::cout;
using std::cin;
using std::string;
using std::endl;

void dayOfWeek::setDay(string d)
{

day = d;

}

string dayOfWeek::getDay()
{
return day;
}

void dayOfWeek::printDay()
{
cout << "The day is " << day << endl;

}



Get rid of this line:
#include "dayOfWeekImp.cpp"
Thanks Return 0. That was so simple I feel kinda dumb now. So I guess the explanation is that because the functions are being called as part of the class "dayOfWeek" there's no need to include the implementation file in main. It's all really part of the class which is already included with the dayOfWeek.h file? Anyway, thanks for pointing that out. It all works perfectly now.
Topic archived. No new replies allowed.