想声明全局的结构体变量,在StdAfx.h中声明
struct s
{
  int x;
}s;
extern s a;
在StdAfx。cpp中声明
s a;那我要在Dialog里给s.a赋值应该在什么地方赋值?我试了下不管放什么地方都会出现下边的错误
error C2146: syntax error : missing ';' before identifier 'a'
error C2371: 's' : redefinition; different basic types
        stdafx.h(146) : see declaration of 's'
fatal error C1004: unexpected end of file found改怎么赋值啊

解决方案 »

  1.   

    struct _s
    {
      int x;
    }s;
      

  2.   

    struct s{
      int x;
    }s;按1楼的方法修改即可.
      

  3.   

    只加个typedef 即可,其他地方不用修改
    typedef struct s
    {
      int x;
    }s;
    上面代码中两个s虽然容易混淆,但可以这么写,最好这样
    结构体名字和变量名区分开如:ypedef struct __S//结构体名
    {
      int x;
    }s //变量;
      

  4.   


    typedef struct _tagS
    {
      int x;
    }S, *PS;
    这是规范,呵呵  看看编程规范就可以啦
      

  5.   

    在CXXPro中声明struct ROLEINFOMSG  
    {
    DWORD soldID;
    ROLEINFOMSG ()
    {
    soldID = 0;
    }
    };在CPP文件
    ROLEINFOMSG *roleInfoMsg = new ROLEINFOMSG();在工程头文件引用
    extern ROLEINFOMSG *roleInfoMsg;
    这样就没有问题了