How code must be to not have multiple definitions of var?

Hello,
In code i don't understud how code must be to not have multiple definition of var?
If i have a function how i must put?

memory.h
1
2
3
4
5
#ifndef MEMORY_INCLUDED
#define MEMORY_INCLUDED
int var;
int modifyC ( );
#endif // MEMORY_INCLUDED 

memory.cpp
1
2
3
4
5
6
#include "memory.h"
int modifyC ( )
{
    var = 3;
    return 0;
}

a.h
1
2
3
4
#ifndef A_H
#define A_H
int modifyA ( );
#endif // A_H 

a.cpp
1
2
3
4
5
6
7
#include "memory.h"
#include "a.h"
int modifyA ( )
{
    var = 1;
    return 0;
}


b.h
1
2
3
4
#ifndef B_H
#define B_H
int modifyB ( );
#endif // B_H 

b.cpp
1
2
3
4
5
6
7
#include "memory.h"
#include "b.h"
int modifyB ( )
{
    var = 2;
    return 0;
}

main.cpp
1
2
3
4
5
6
7
8
9
10
#include "memory.h"
#include "a.h"
#include "b.h"
#include <stdio.h>
int main ()
{
    modifyA ( );
    modifyB ( );
    modifyC ( );
    return 0;

Last edited on
http://www.cplusplus.com/forum/general/140198/ (global variables)
don't forget to define the variable. By instance in memory.cpp int var;

Also, consider to not use global variables.
Topic archived. No new replies allowed.