以MyApp.h中CMyApp类的外面定义应该就可以了。

解决方案 »

  1.   

    在外部定义所需全局变量,其作用域是整个程序
    在其它文件中要引用此全局变量需声明extern
      

  2.   

    可以在一个.cpp中定义,其他.cpp用extern  
      

  3.   

    以上各位的方法都可行,也可以在CMyApp中定义PUBLIC变量,别处用时用((CMyApp*)AfxGetApp)->变量名字
      

  4.   

    新建一.h文件在其中定义变量在其它类中加入#include "*.h"即可
      

  5.   

    You can use the variables in CApp
      

  6.   

    step1.在类的定义中(*.h)
    定义变量或函数,并在类型前声明为static
    step2.在类的实例中(*.cpp)声明
    在.cpp文件的开始在次声明。
    类型 类名:变量名/函数定义。
    step2.调用方法
    在其他的调用.cpp中直接使用“类名::变量名/函数“
    Sample
    step1.
    // myclass.h
    class myclass
    {
    ...
    public:
    static int g_count; // 全局变量
    static void callfunction(int &a, char * buf); // 全局函数
    ...
    };
    step2.
    //myclass.cpp
    ...
    #include "myclass.h"
    ...
    // 声明为全局的变量或函数
    int myclass::g_count;
    void myclass::callfunction(int& a, char* buf);///////////////////////////
    myclass::myclass()
    {
    }
    myclass::~myclass()
    {
    }
    ...step3.
    // other.cpp
    ...
    #include "myclass.h"
    ...void other::load()
    {
     int k = myclass::g_count;
     k ++;
     int a = 0;
     char buffer[1024] = "";
     myclass::callfunction(a,buffer);
     return;
    }
    有问题Please Mailto [email protected]