Advertisement

Real Easy Annoying Question

Started by July 14, 2000 10:12 PM
1 comment, last by Chipcrap 24 years, 5 months ago
ARRRGHHHHH! OK I''m using MS Visual C++ 6, These are the files in my Project- Source Files: Tetris.cpp External Dependencies: Graphics.cpp, Graphics.h The compile works fine like this-except everytime I make a change to Graphics.cpp. I have to save, exit, restart the compiler, and re-compile. If I move Graphics.cpp to Source files, and Graphics.h to Header Files I get a billion errors saying everything is allready defined in Tetris.obj. I tried deleting Tetris.obj, but that didn''t help. I tried starting a new project and cutting and pasting all the code and that didn''t help. Tetris.cpp has #include<"Graphics.cpp">, and Graphics.cpp has #include<"Graphics.h">. Somebody help-this is driving me batty and I know ist something simple! Thanks
hmmm, my first guess is that your forgot to define your header file.

//headef file

#ifndef HEADERFILE
#define HEADERFILE


//code



#endif


Also, your include should be

#include "filename" or
#include

When you use the double quotes, the compiler first looks in the projects directory or starting in the project directory.

the tells the compiler to look in the include path specified in the compiler options.

Last thing, you should not include the .cpp file. You should include the .h in tetris.cpp. This is probably why you get those errors:

if graphics.cpp is included in tetris.cpp, that means that all the functions definitions of graphics will be included. So when tetris.cpp is compiled, all the functions in graphic.cpp are also compiled. So when comes the time to compile graphics.cpp, then the compiler will complain that it is already done!

So you need to include the header wich should contain all the functions declarations you need and let the compiler do the linking.
Advertisement
Thanks-That helped out alot-The compiler is smarter than I thought. I didn''t realize that it would compile my 2nd cpp file even if it''s not included-THANK YOU!

This topic is closed to new replies.

Advertisement