多个CPP文件都可以用到?WIN32程序.

解决方案 »

  1.   

    随便在一个CPP文件的函数体的外面的任何地方定义变量,比如:int a;
    在别的CPP文件中要有时先用extern声明一下,比如在另一个CPP中要用这个a,可以extern int a;
    下面就可以用了.
      

  2.   

    头文件中加 extern int a;如果在dll中药加 dllexport 
    cpp文件中 extern int a = 0 ; include 头文件就可以使用了欢迎访问我的网站, www.nunew.com,刚注册的,自己开发了一个插值软件。
      

  3.   

    现在三个文件a.app a.h b.app
    a.app
    void GetVar()
    {
        _cName="sdddd";
    }a.h
    void GetVar();
    #ifndef Test
    #define Test
    static char _cName[1024];
    #endifb.app
    int Message(char* str)
    {
        MessageBox(NULL, _cName, "Test", MB_OK);
    }在执行b.app的Message时_cName总是为空,不知为啥?
      

  4.   

    现在三个文件a.app a.h b.app 
    a.app 
    void GetVar() 

        _cName="sdddd"; 
        MessageBox(NULL, _cName, "Test", MB_OK); 

    a.h 
    void GetVar(); 
    #ifndef Test 
    #define Test 
    static char _cName[1024]; 
    #endif 
    b.app 
    int Message(char* str) 

        MessageBox(NULL, _cName, "Test", MB_OK); 
    } 在执行a.app的GetVar时_cName是对的。
    在执行b.app的Message时_cName总是为空,不知为啥?
      

  5.   

    当我把a.h改为
    void GetVar(); 
    #ifndef Test 
    #define Test 
    extern char _cName[1024]; 
    #endif 调试报错
    unresolved external symbol "char * _cName" (?_LogFileName@@3PADA)IDE:VC6
      

  6.   

    a.h 
    void GetVar(); 
    #ifndef Test 
    #define Test 
    static char _cName[1024]; 
    #endif 
    =========
    不是这样的定义的,对于全局变量是不能是头文件中定义的,头文件中可以声明一下,但是不能定义,
    直接在a.cpp中定义,
    在b.cpp中用之前,在某个空白地方加一句:extern char  _Name[1024]即可.
    你在a.h中定义了,估计a.h你在两个CPP文件中都引用了吧,这样,就成了两个不同的变量了.
      

  7.   

    在 b.cpp中开始的地方加 _cName="sdddd"; 定义了静态变量怎么能不初始化!