locked
Define a Global Variable for all .cpp files RRS feed

  • Question

  • In the name of god

    have a good time

    I want to define a variable for all .cpp files in my project, but i couldn't do it.

    I tried a header file and put the variable on it ,also write the "#pragma once" at first of that and use #include"header.h" for all .cpp files, but it didn't work.

    can you help me please?

    e-mail : m.nejadsahebi@live.co.uk

    thanks in advance

    Monday, November 11, 2013 7:44 AM

Answers

  • Add a .cpp file for you global variables:

    #include “stdafx.h”
    #include “header.h”
    
    int myGlobalVariable1;
    char myGlobalVariable2;
    

    The “header.h” file:

    #pragma once
    
    extern int myGlobalVariable1;
    extern char myGlobalVariable2;
    

    If still does not work, then show the error messages.


    Monday, November 11, 2013 7:57 AM