新建一个多文档应用程序,直接在Doc.h中声明一个变量,例如int a;链接为什么报错error LNK2005,如何解决?

解决方案 »

  1.   

    --------------------Configuration: test00 - Win32 Debug--------------------
    Linking...
    test00Doc.obj : error LNK2005: "int a" (?a@@3HA) already defined in test00.obj
    test00View.obj : error LNK2005: "int a" (?a@@3HA) already defined in test00.obj
    Debug/test00.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.test00.exe - 3 error(s), 0 warning(s)
      

  2.   

    你这个是重复定义啊,你是将int a;写在H文件中了吧,H文件可能被引用了多次,就形成了重复定义,写在CPP中吧
      

  3.   

    int a;
    两个全局变量重定义了.
      

  4.   

    变量定义在.h头文件里了。
    头文件被多个.cpp文件包含了,重复定义了。
    不要在头文件里定义变量。