Advertisement

Multiple cpp files in MSVC 6.0

Started by July 29, 2000 05:59 AM
16 comments, last by MarkO 24 years, 4 months ago
for simple C style structs, you can just include the other header after the typedefs.

for classes, you need to put a class Matrix; before the Vector class def, like this (i think)

    #ifndef VECTOR_H#define VECTOR_H#include "matrix.h"class Matrix;class Vector{    //stuff here};#endif    
yoo DO NOT need extern for your function declarations or implementations even though they are called from another source file


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Advertisement
Thanx alot guys!

Greets,XBTC!
uh, after reading all the articles, I still cannot clear my problem. I got a strange problem in Creating Surface with DirectDraw.

My project base in Multiple file.
There are 6 files in the project

unit.h //define the UNIT functions based in Class structure.
unit.cpp //the UNIT Class.
ddrawex.h //define the DDraw functions.
ddrawex.cpp //the DDraw functions. ( contest of Create Surface function. )
main.h //include "unit.h" and "ddrawex.h"
main.cpp //main program.

In the "unit.cpp" and "ddrawex.cpp" have codes following:

#include "main.h"

that''s the way I make them liked.
But If I define the LPDIRECTDRAW in "main.h" , then the compiler said "it''s already defined in ddrawex.cpp and unit.cpp" (Because they all include the "main.h") .
how to make the LPDIRECTDRAW structure become a global variable?


Make sure your linking the right wrapper... In project -> settings -> link and in the libraries list, include your ddraw lib there. Make sure that the directory of this lib is at the top of your list in the Directories tab... DirectX always seems to be a bitch about this


-Chris Bennett ("Insanity" of Dwarfsoft)

Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
First, if you want to make that LPDIRECTDRAW be global, you would need to use EXTERN, however, there should be one place where this file is just declared normally (i.e. WITHOUT the extern).....

so, lets say you want the LPDIRECTDRAW to be in, ddrawex.h....



//main.h
#ifndef MAIN_H
#define MAIN_H

#include "ddrawex.h"
#include "unit.h"

LPDIRECTDRAW something;

#endif


//ddrawex.h
#ifndef DDRAWEX_H
#define DDRAWEX_H

#include "main.h"

extern LPDIRECTDRAW something;

//Whatever else you need here..
#endif


//unit.h
#ifndef UNIT_H
#define UNIT_H

#include "main.h"
extern LPDIRECTDRAW something;

//Whatever else goes here...
#endif


then, in your .cpp files, just include the corresponding header.

(e.g.)
in UNIT.CPP, do: #include "unit.h"


I MAY not be 100% right on the use of externs when you include them in header files. If for some reason this doesn''t work, simply OMIT any line in the above header files that have extern LPDIRECTDRAW something.... But keep the one that DOESN''T start with extern....

Hope this helps?!

Mihkael


Advertisement
Sorry, that was me above...

Omit the comment about if you want to have LPDIRECTDRAW in ddrawex.h... Sorry.

Mihkael
woohoo thanks Mihkael for the help I tried the steps you gave and finnaly got my code to work with a second cpp file. I used extern in my two header files and defined them in one of my cpp files. Weeks of frustration finnaly over.

This topic is closed to new replies.

Advertisement