Re: [Dev-C++] Project in DevCpp4 (files 'n stuff)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: graeme <gr...@dr...> - 2001-09-28 02:20:38
|
>I having serious problems with my projects... I would like to split my code
>up into some different files, to make it more ease to navigate. But, when I
>put functions all around different files, they cant call eachother, if that
>makes any sense.
file02.cpp needs to know about function bob which is defined in file
file02.cpp. However it is much better practice to #include header files, the
header files will then include the prototype of the functions that you wish
to call hence:
main.cpp:
#include "file02.hpp"
// Note don't need to include file01.hpp because this file only uses weird
void main(void)
{
weird(); //works Ok :/
}
file01.hpp:
void bob(void);
file02.cpp:
void weird(void);
file01.cpp:
#include "file01.hpp"
void bob(void)
{
blabla
}
file02.cpp:
#include "file01.hpp"
#include "file02.hpp"
// Need to include file02.hpp because of the call to bob.
void weird(void)
{
bob(void) //isn't working!
}
Hope that helps. Once you get that working you might want to consider using
pre-processor directives to conditionally include a header file these are
useful to avoid declaring the contents of a header file more than once in a
programme and follow a standard template:
#ifndef __FILE01_HPP__
#define __FILE01_HPP__
// include the header file declarations here
#endif
Cheers,
Graeme.
|