Results 1 to 3 of 3

Thread: [RESOLVED] #define not working between includes

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] #define not working between includes

    I have the following code on my main.cpp:

    Code:
    #ifdef _WIN64
    #define hOS 1
    #elif _WIN32
    #define hOS 1
    #elif __APPLE__
    #define hOS 2
    #elif __linux
    #define hOS 3
    #else
    #define hOS 0
    #endif
    
    #include "functions.h"
    functions.h:
    Code:
    #ifndef _FunctionsFile
    #define _FunctionsFile
    
    #include <string.h>
    #include <iostream>
    
    using namespace std;
    
    void someFunction(bool someParameter);
    
    #endif
    functions.cpp:
    Code:
    #include "functions.h"
    void someFunction(bool someParameter= false)
    {
      if (hOS==1)
      {
        std::cout<<"Windows";
      }
    }
    When trying to complile I get this error in functions.cpp:
    C:\Dev\CPP\functions.cpp `hOS' undeclared (first use this function)

  2. #2
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: #define not working between includes

    Hey
    its a long long time that i didnt use c++ but as far as i remember #include MOST always be the first thing that u are writing then define

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: #define not working between includes

    Hey monk,

    Thanks for the reply! It seems you must #define on every page that wants it, it, including a page doesn't carry over its defines. All fixed though =).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width