2013-04-29 140 views
0

静态误差:静态成员变量出口

in test1.dll: 
    xxx.h 
    class AFX_EXT_CLASS CTest1 
    { 
     static int num; 
    } 

    xxx.cpp 
    int CTest1::num = 0; 

    in a cpp of test2.dll: test2 is dependent test1.dll 
    ... 
    int i = CTest1::num; 
    ... 

    in a cpp of App: App is dependent test1.dll & test2.dll 
    ... 
    int i = CTest1::num; 
    ... 
在test2.dll

“未解析的外部符号” 静态:CTest1 :: NUM。 但在App中,没问题。

顺便说一句:如果我使用CTest1的其他功能,没问题。

帮助我,非常感谢。

+0

为什么不使用'extern'关键字? – 2013-04-29 14:35:25

回答

0

编译器正在剥离符号。你可以试试__declspecimport。您也可以尝试extern变量并在另一个项目中创建人工参考。

+0

我已经测试过了,没关系!非常感谢! – user2304377 2013-04-29 23:03:07