Multiple definition of class.

I have a error named "Multiple definition of class" and i really don't understand where is problem.

It says error is here:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <time.h>
#include "pokoje.h"
using namespace std;

  void Pokoje::charastats()
{
    cout << "Numbers of entered rooms: "<<nop<<"\n"; 

}

Also, i have a header file with:
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
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <time.h>

#ifndef POKOJE_H_INCLUDED
#define POKOJE_H_INCLUDED

using namespace std;

class Pokoje
{
    public:
    char movee; // have key that you clicked
    int nop; // number of rooms that we entered
    int r1,r2,r3,r4; // for random functions
    int x,y; // map localization
    int enemy; // if enemy can appear
    int chara; // character
    void enemyappear(); // enemies !
    void charastats(); //character stats for example number of rooms
    void  roomenter(); //enter rooms function
    void  movement(); //move character
    void roomsgen(); // random rooms
    void bossrooms(); // boss rooms
};
#endif // POKOJE_H_INCLUDED 


This error is in every void in my .cpp file. Help

edit: Here is code in main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <windows.h>
#include <conio.h>
#include "pokoje.cpp"
#include "pokoje.h"
#include <time.h>

using namespace std;

int main()
{
    Pokoje p1;
    p1.roomenter();
    p1.roomsgen();
    p1.charastats();
    p1.nop = 0;
    while(true)
    {
        p1.movement();
    }
    return 0;
}

Last edited on
main.cpp?

sorry I had not seen. :)
Last edited on
Hello ASCIIIsVeryHelpful,

I have a error named "Multiple definition of class". Which class has the multiple definition?

In you header file you have:

1
2
3
4
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <time.h> 


very nice, but these header files are not needed in your header file and should not be there along with using namespace std;. Your multiple definition is most likely coming from those header files being included in your program for the second time and not from what you have created.

When I tested what you have posted removing the includes from the header file it compiled with no errors.

Hope that helps,

Andy
In this code its only this class, and after removing includes and compiling error is still here.
When im compiling, its says:
"Multiple definition of 'Pokoje::charastats'"
and then
"first defined here"

These messenges are placing me in the same line of code.
Hello ASCIIIsVeryHelpful,

Now I see it. It is line 4 in main. You do not need to include this in main, only when the needed files or project is compiled. Remove line 4 and you error should go away.

Hope that works,

Andy
Thanks Andy, its working!
Your Welcome.

Andy
Topic archived. No new replies allowed.