There is a question which make me puzzle. I know it is not right to do that ,but I don't know why. And how does the #ifndef #define #endif work.How the compliers deal with the varialbles like the following "a" and "b" ;
The code is simple:(myh.h):
using namespace std;
First, about the compilation:
You´ve to understand that the compiler will compile every cpp-file separately first
(before they go all together in a executable during the linking process)
If you have a file main.cpp and two times a
#include <abc.h> in it,
you can prevent the second include to give errors with your
If you have a main.cpp which includes
#ifndef etc. will help too.
But: As cpp-files (together with included headers) are processed separately,
it won´t help if you include the same header file in different cpp files.
Ie. you may include headers as much as you want, but they shouldn´t contain variables.
About your second question: P is only a "description" what a "P" should be.
(every P has a
int a. But at that time, there is no P.).
b is an actual int which can hold numbers...