need help with classes

So basically, this is the scenario
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
////////////////////////////////////////////////
//A.h
Class A
{
public:
.
.
.
};

///////////////////////////////////////////////
//B.h
Class B
{
public
.
.
.
};

///////////////////////////////////////////////
B.cpp

A objectOfA;

void B::func()
{
     //This function uses the object objectOfA
}

///////////////////////////////////////////////
main.cpp

A objectOfA;

int main( argc ... )
{
     /// tries to use the objectOfA object
}

and my errors say
 
objectOfA uses undefined class 'A'

and
 
left of '.memberFunctionOfA' must have class/struct/union



What Do?!
Last edited on
Did you not include A.h?
Yeah its included.

Is it because i included A in B and B in A?
Okay i fixed the first problem but now im getting these errors

1
2
3
4
5
6
7
8
9
10
11
12
13
1
1>  main.cpp
1>main.obj : error LNK2005: "union SDL_Event event" (?event@@3TSDL_Event@@A) already defined in Board.obj
1>main.obj : error LNK2005: "struct SDL_Surface * X" (?X@@3PAUSDL_Surface@@A) already defined in Board.obj
1>main.obj : error LNK2005: "struct SDL_Surface * O" (?O@@3PAUSDL_Surface@@A) already defined in Board.obj
1>main.obj : error LNK2005: "class Screen myScreen" (?myScreen@@3VScreen@@A) already defined in Board.obj
1>Screen.obj : error LNK2005: "union SDL_Event event" (?event@@3TSDL_Event@@A) already defined in Board.obj
1>Screen.obj : error LNK2005: "struct SDL_Surface * X" (?X@@3PAUSDL_Surface@@A) already defined in Board.obj
1>Screen.obj : error LNK2005: "struct SDL_Surface * O" (?O@@3PAUSDL_Surface@@A) already defined in Board.obj
1>Screen.obj : error LNK2005: "class Screen myScreen" (?myScreen@@3VScreen@@A) already defined in Board.obj
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>c:\users\david\documents\visual studio 2010\Projects\Tic-Tac-Toe\Debug\Tic-Tac-Toe.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Looks like you're including headers more than once? Try using #pragma once in your header files maybe?
Nope. Still does the same error :(
Is it because i included A in B and B in A?
¿why did you do that?
http://www.cplusplus.com/articles/Gw6AC542/ (especially points 4 and 6)

Please post something that reflect your issue. http://www.cplusplus.com/forum/articles/40071/#msg216313
Okay, maybe this will clear things up.

screen.cpp
#include screen.h
#incldue board.h

board.cpp
#include board.h

screen.h
#include SDL and SDL extensions
#intclude string
#include iostream

board.h
#include screen.h

main.cpp
#include "Screen.h"
#include "Board.h"
#include <string>

both header files use #ifndef #define #pragma once #endif IN THAT ORDER
¿Are you defining global variables in your cpps?
If you want them to be local use static, (extern for shared, or better pass it as an argument)
nope no global variables.
1
2
3
4
union SDL_Event event;
struct SDL_Surface * X;
struct SDL_Surface * O;
class Screen myScreen;
¿what are those? ¿where and how they are defined?
Topic archived. No new replies allowed.