导出类
为什么能够这样定义
    class __declspec( dllexport ) CMyClass;
 而不能
    __declspec( dllexport ) class  CMyClass;
但是变量导出方式下面两种方法皆可呢?
   
__declspec( dllexport ) int nLen;int __declspec ( dllexport) nLen;

解决方案 »

  1.   

    导出类
    class AFX_EXT_CLASS CMyClass;
      

  2.   

    class __declspec( dllexport ) CMyClass;这种模式好象是VC特有的
      

  3.   

    到处变量:
       AFX_EXT_DATA
      

  4.   

    我问的是
          为什么   class __declspec( dllexport ) CMyClass; 可以
          而      __declspec( dllexport ) class  CMyClass;不可以
    但是  
        为什么对于导出变量nLen两种方式都可以
      

  5.   

    class __declspec( dllexport ) CMyClass;这种模式好象是VC特有的
    人家不都告诉你了吗?怎么还问。就像你定义类为什么要用class呀,你要人家怎么给你解释呀?
      

  6.   

    找到答案,共享给大家
    The __declspec keywords should be placed at the beginning of a simple declaration. THe compiler ignores, without warning, any __declspec keywords placed after * or & and in front of the variable identifier in a declaration.A __declspec attribute specified in the beginning of a user-defined type declaration applies to the variable of that type. For example:__declspec(dllimport) class X {} varX;
    In this case, the attribute applies to varX. A __declspec attribute placed after the class or struct keyword applies to the user-defined type. For example:class __declspec(dllimport) X {};
    In this case, the attribute applies to X.to taoni(taoni)你现在明白我为什么还要问了么?
      

  7.   

    from MSDNThe __declspec keywords should be placed at the beginning of a simple declaration. THe compiler ignores, without warning, any __declspec keywords placed after * or & and in front of the variable identifier in a declaration.A __declspec attribute specified in the beginning of a user-defined type declaration applies to the variable of that type. For example:__declspec(dllimport) class X {} varX;
    In this case, the attribute applies to varX. A __declspec attribute placed after the class or struct keyword applies to the user-defined type. For example:class __declspec(dllimport) X {};
    In this case, the attribute applies to X.The general guideline for using the __declspec attribute for simple declarations is as follows:decl-specifier-seq init-declarator-list;The decl-specifier-seq should contain, among other things, a base type (e.g. int, float, a typedef, or a class name), a storage class (e.g. static, extern), or the __declspec extension. The init-declarator-list should contain, among other things, the pointer part of declarations. For example:__declspec(selectany) int * pi1 = 0;   //OK, selectany & int both part of decl-specifier
    int __declspec(selectany) * pi2 = 0;   //OK, selectany & int both part of decl-specifier
    int * __declspec(selectany) pi3 = 0;   //ERROR, selectany is not part of a declarator