I will not say how far I have got so far, because i'll proberbly jsut confuse myself. Could somebody please clearly explain on how I could get one function that can be called, from any number of files ?
I will not say how far I have got so far, because i'll proberbly jsut confuse myself. Could somebody please clearly explain on how I could get one function that can be called, from any number of files ?
Code:// header.h #ifndef HEADER_H #define HEADER_H void f(); // Prototype #endifNow just include header.h wherever you want to use f, and compile header.cpp with the rest of your source files.Code://header.cpp #include "header.h" // Definition void f() { ... }
My best code is written with the delete key.
As you can quite obviously see, i am a newbie.
what does this part of the header file mean ? :
#ifndef HEADER_H
#define HEADER_H
that says that if HEADER_H is not defined then define it. If it is defined ignore to the #endif.
Look up preprocessor commands in your favourite text or your help files.
This is a schema for preventing cyclic includes.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
ahh, so am I right in saying that it stops er, processing the header file if its included in multipul c files ?
also, ( im very, very new to this ), can I include functions like :
or, am I only allowed to prototype functions in a .h file ?Code:void f(void) { << cout " I called this function"; }
>can I include functions like
You can, but you shouldn't. Headers should contain only declarations.
>so am I right in saying that it stops er, processing the header file if its included in multipul c files ?
Preprocessing, actually. If the header was previously included, HEADER_H will be defined and the #ifndef will fail, thus bypassing everything up to the #endif.
My best code is written with the delete key.
Excelent, thank you so much for the help. I so glad I didnt get any ' newbie / rtfm ' comments, and got mature and helpfull responses - thanks.
Ill come here again for my c++ questions, what an excelent support site.
>I so glad I didnt get any ' newbie / rtfm ' comments
We only give those comments to people who deserve them.
>and got mature and helpfull responses
Good questions receive good answers.
My best code is written with the delete key.